473,785 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onkeypress store previous value of a variable

8 New Member
How store the previous value of a variable when i use onkeypress event in javascript
Mar 10 '08 #1
4 3161
gits
5,390 Recognized Expert Moderator Expert
hi ...

please explain the requirement in more detail and post some code you probably already have ...

kind regards
Mar 10 '08 #2
sunita jadhav
8 New Member
How i store the previous value of temp when key is press i got next value of temp but also want the previous value of temp. plz reply me

[HTML]<html>
<head>
<script type="text/javascript">

var cnt=0;
var inc=0;

var strSeparatorArr ay=new Array("-","/","!","@","#"," $","%","^","&", "*","(",")","_" ,"+","+","|",": ","{","}","[","]","?","."," ,"," ","'","~");

function checkdate(objNa me,e,format)
{
var strDateformate;
var strDate;
var strDateArray;
var intYear;
var datefield = objName;
var strInd=0;
var tokInd=0;
var temp;

dateStr=documen t.getElementByI d("datetext").v alue;
strDate = datefield.value ;

//Get Separator from format string.
strDateformat = format;
for (var i= 0; i < strSeparatorArr ay.length; i++)
{
if (strDateformat. indexOf(strSepa ratorArray[i]) != -1)
{

sep_char=strSep aratorArray[i];
pos=strDateform at.indexOf(sep_ char);
break;
}
}

//Get token from format string.
tokArr=format.s plit(sep_char); alert(tokArr[0].length)
for(var i=inc;i<tokArr. length;i++)
{
for(var j=0;j<tokArr[i].length;j++)
{
temp=tokArr[i];
break;
}
inc++;
break;
}

var currtemp = (window.Event) ? e.which : e.keyCode;
currkey=String. fromCharCode(cu rrtemp);


switch (temp)
{

case 'd':
case 'D':
datefield.value +=currkey+sep_c har;
break;

case 'dd':
case 'DD':
if(datefield.va lue.charAt(0)== 1 || datefield.value .charAt(0)==2)
{

datefield.value +=currkey+sep_c har;
}
else
if(datefield.va lue.charAt(0)== 3)
{
if(currkey<=1)
datefield.value +=currkey+sep_c har;
else
return false;
}
else
{
if(currkey==1 || currkey==2 || currkey==3)
datefield.value +=currkey;
else
datefield.value +='0'+currkey+s ep_char;
}
break;

case 'm':
case 'M':
datefield.value +=currkey+sep_c har;
break;

case 'mm':
case 'MM':
if(datefield.va lue.charAt(0)== 1)
{
if(currkey==0|| currkey==1||cur rkey==2)
datefield.value +=currkey+sep_c har;
else
return false;
}
else
{
if(currkey==1)
datefield.value +=currkey;
else
datefield.value +='0'+currkey+s ep_char;
}
if(datefield.va lue.charAt(3)== 1)
{
if(currkey==0 || currkey==1 ||currkey==2)
datefield.value +=currkey+sep_c har;
else
return false;
}
break;

case 'y':
case 'Y':
if(datefield.va lue.length==3)
{
datefield.value +=currkey+sep_c har;
}
else
{
datefield.value +=currkey;
}
break;

case 'yy':
case 'YY':
if(datefield.va lue.length==1)
{
datefield.value +=currkey+sep_c har;
}
else
{
datefield.value +=currkey;
}
break;

case 'yyyy':
case 'YYYY':
if(datefield.va lue.length==3)
{
datefield.value +=currkey+sep_c har;
}
else
{
datefield.value +=currkey;
}
break;
}
tokInd++;
window.event.ke yCode=13;
}// end of function checkdate

</script>
</head>
<body>
Date :-<br>
<input type=text id=datetext name=datetext onkeypress="che ckdate(this,eve nt,'mm/dd/yyyy')"/>
</body>
</html>[/HTML]
Mar 11 '08 #3
vee10
141 New Member
Hi,

if u want to store any previous value u can use cookie object

document.cookie =store the value

u can check how to use cookies in http://echoecho.com/javascript.htm
Mar 11 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Merged threads on the same topic. Do not double post.

Also remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

Finally, remember to use [code] tags when posting code.

Thanks, moderator.
Mar 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
9780
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ? window.event : "") ...
9
1932
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using top.A.tableVar = document.getElementById("someTable"); As long as Frame B is *not* 'refreshed/ reloaded' witk another page the
2
11129
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a tutorial/guide?
12
2277
by: harishg2 | last post by:
Hi, How to store a variable value for more than one executions. Ex: main() { int i=0; i++; printf("%d",i);
3
5175
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. The "<body.." tag in each frame includes an "onKeyPress" handler to catch and act on key presses. And if I focus the window by clicking on the content of one of the documents, keystrokes are sent to the handler on its "<body..." tag.
1
7496
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works fine the first time (when the input-field is created in a non-dynamical way). The next input-field is created dynamically by a function that is called when the user hits enter (the previously generated input-field will be hidden). Then I'm trying...
0
1553
by: seep | last post by:
salam to everyone.. as a new bee in .net i m finding lot of difficulty. i want to get all records of a table from database via store procedure.but spending many days i dont know how can i do that. some work that i do is: Imports System
4
2208
by: wish | last post by:
Hi all, Where is the location for store session variable? Because i feel that the session variable is keep store the previous variable and no release the variable. When i click back button, the page that is no i wan and i go to the previous page. Is it useful i add code the clear session variable on every page that is use session variable?
5
22024
by: hannie | last post by:
onKeyPress does not work in Firefox. If use tab to navigate each field and press "Enter" on "Next" button to submit form and process to the next form / page, IE works well even if without onKeyPress code. However, Firefox supresses onKeyPress on submit when "Enter" key is pressed. e.which and code="13" does not work for submit button at all in Firefox nor by changing code to focus(). e.g. use tab to navigate each field, when tab goes...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.