473,500 Members | 1,898 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 3156
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 strSeparatorArray=new Array("-","/","!","@","#","$","%","^","&","*","(",")","_","+", "+","|",":","{","}","[","]","?",".",","," ","'","~");

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

dateStr=document.getElementById("datetext").value;
strDate = datefield.value;

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

sep_char=strSeparatorArray[i];
pos=strDateformat.indexOf(sep_char);
break;
}
}

//Get token from format string.
tokArr=format.split(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(currtemp);


switch (temp)
{

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

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

datefield.value+=currkey+sep_char;
}
else
if(datefield.value.charAt(0)==3)
{
if(currkey<=1)
datefield.value+=currkey+sep_char;
else
return false;
}
else
{
if(currkey==1 || currkey==2 || currkey==3)
datefield.value+=currkey;
else
datefield.value+='0'+currkey+sep_char;
}
break;

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

case 'mm':
case 'MM':
if(datefield.value.charAt(0)==1)
{
if(currkey==0|| currkey==1||currkey==2)
datefield.value+=currkey+sep_char;
else
return false;
}
else
{
if(currkey==1)
datefield.value+=currkey;
else
datefield.value+='0'+currkey+sep_char;
}
if(datefield.value.charAt(3)==1)
{
if(currkey==0 || currkey==1 ||currkey==2)
datefield.value+=currkey+sep_char;
else
return false;
}
break;

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

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

case 'yyyy':
case 'YYYY':
if(datefield.value.length==3)
{
datefield.value+=currkey+sep_char;
}
else
{
datefield.value+=currkey;
}
break;
}
tokInd++;
window.event.keyCode=13;
}// end of function checkdate

</script>
</head>
<body>
Date :-<br>
<input type=text id=datetext name=datetext onkeypress="checkdate(this,event,'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
9752
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) ?...
9
1905
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...
2
11103
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...
12
2238
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
5142
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. ...
1
7474
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...
0
1528
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...
4
2188
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,...
5
22001
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...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
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...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
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...
0
7397
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...
1
4923
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...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
316
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...

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.