my question is if i type in html textbox on key press event suppose i type 12345 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i have face problem that is if i insert 6 at 3 this value is not insert at 3 it insert last positon i.e after last value .In given example the value is appned or insert after 5 then output is 12456 but i have want the output 12645 and i also give the maxlength to textbox. so plz help me.
textfield issue on key press - digit insert problem at editing position
Collapse
X
-
Tags: None
-
textfeild issue on key press
my question is if i type in html textbox on key press event suppose i type 12/03/2008 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i have face problem that is if i insert 6 at 3 this value is not insert at 3 it insert last positon i.e after last value .In given example the value is appned or insert after 5 then output is 12/0/20006 but i have want the output 12/06/2008 and i also give the maxlength to textbox. so plz help me
my code is giveing below
[HTML]<html>
<head>
<script type="text/javascript">
var len1=0;
var len2=0;
var strSeparatorArr ay=new Array("-","/","","!","@","# ","$","%","^"," &","*","_","+", "|",":","\","," ?",".",","," ","'","~");
function checkdate(objNa me,e,format)
{
var length;
var strDateArray;
var cutoffyear=50;
var first_token;
var second_token;
var third_token;
var tokArr= new Array();
length=parseInt (objName.value. length);
var string=document .getElementById ("datetext").va lue;
//Get Separator from format string.
for (var i= 0; i < strSeparatorArr ay.length; i++)
{
if (format.indexOf (strSeparatorAr ray[i]) != -1)
{
sep_char=strSep aratorArray[i];
break;
}
}
tokArr=format.s plit(sep_char);
first_token=tok Arr[0];
second_token=to kArr[1];
third_token=tok Arr[2];
if(sep_char=="" )
sep_char="/";
len1=first_toke n.length;
len2=second_tok en.length;
var currtemp = (window.Event) ? e.which : e.keyCode;
currkey=String. fromCharCode(cu rrtemp);
//if(length<forma t.length)
{
if(!isNaN(currk ey) && e.keyCode!=32 && e.keyCode!=13 && e.which!=32)
{
if(length<len1)
{
switch(first_to ken.toUpperCase ())
{
case 'DD':
if(length==0)
{
if(currkey=='0' || currkey=='1' || currkey=='2' || currkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==1)
{
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1' || string=='2')
objName.value+= currkey+sep_cha r;
if(string=='3' && (currkey=='0' || currkey=='1'))
objName.value+= currkey+sep_cha r;
}
break;
case 'MM':
if(length==0)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
t_flag1=false;
}
if(length==1)
{
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
else
if(string=='1' && (currkey=='0'|| currkey=='1'||c urrkey=='2'))
objName.value+= currkey+sep_cha r;
}
break;
case 'YY':
if(length==0)
objName.value+= currkey;
if(length==1)
objName.value+= currkey+sep_cha r;
break;
case 'YYYY':
if(length==0 && currkey!=0)
objName.value+= currkey;
if(length==1 || length==2)
objName.value+= currkey;
if(length==3)
objName.value+= currkey+sep_cha r;
break;
}
}
else
{
if(length>len1 && length<=len1+le n2)
{
switch(second_t oken.toUpperCas e())
{
case 'DD':
if(length==3)
{
if(currkey=='0' ||currkey=='1'| |currkey=='2'|| currkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==4)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1'| |string=='2')
objName.value+= currkey+sep_cha r;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey+sep_cha r;
}
if(length==5)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==6)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1'| |string=='2')
objName.value+= currkey+sep_cha r;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey+sep_cha r;
}
break;
case 'MM':
if(length==3)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==4)
{
string=string.s ubstring(string .length-1);
if(string=='0')
objName.value+= currkey+sep_cha r;
if(string=='1'& &(currkey==' 0' || currkey=='1' || currkey=='2' ))
objName.value+= currkey+sep_cha r;
}
if(length==5)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==6)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
else
if(string=='1' &&(currkey== '0' || currkey=='1' || currkey=='2'))
objName.value+= currkey+sep_cha r;
}
break;
}
}
else
{
switch(third_to ken.toUpperCase ())
{
case 'DD':
if(length==6)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
}
if(length==7)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1'| |string=='2')
objName.value+= currkey;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey;
}
if(length==8)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey
}
if(length==9)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1'| |string=='2')
objName.value+= currkey;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey;
}
break;
case 'MM':
if(length==6)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
t_flag3=false;
}
if(length==7)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1' &&(currkey== '1' || currkey=='2' || currkey=='0'))
objName.value+= currkey;
}
if(length==8)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
}
if(length==9)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1' &&(currkey== '1' || currkey=='2' || currkey=='0'))
objName.value+= currkey;
}
break;
case 'YY':
if(length==6 || length==7)
objName.value+= currkey;
break;
case 'YYYY':
if(length==6 &&currkey!=' 0')
objName.value+= currkey;
if(length==7 || length==8 || length==9)
objName.value+= currkey;
break;
}
}
}
}// end of currkey if
}//end of format length if
if(e.keyCode==8 || e.keyCode==37 || e.keyCode==39)
return true;
if(window.event )
window.event.ke yCode=13;
else
return false;
}// end of function checkdate
</script>
</head>
<body>
Date :-<br>
<input type=text id=datetext name=datetext onkeypress="che ckdate(this,eve nt,'mm/dd/yy')"/>
</body>
</html>[/HTML]Comment
-
key press issue on textfeild
my question is if i type in html textbox on key press event suppose i type 12/03/2008 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i have face problem that is if i insert 6 at 3 this value is not insert at 3 it insert last positon i.e after last value .In given example the value is appned or insert after 5 then output is 12/0/20006 but i have want the output 12/06/2008 and i also give the maxlength to textbox. so plz help me
my code is giveing below
Code: [HTML]<html>
<head>
<script type="text/javascript">
var len1=0;
var len2=0;
var strSeparatorArr ay=new Array("-","/","","!","@","# ","$","%","^"," &","*","_","+", "|",":","\","," ?",".",","," ","'","~");
function checkdate(objNa me,e,format)
{
var length;
var strDateArray;
var cutoffyear=50;
var first_token;
var second_token;
var third_token;
var tokArr= new Array();
length=parseInt (objName.value. length);
var string=document .getElementById ("datetext").va lue;
//Get Separator from format string.
for (var i= 0; i < strSeparatorArr ay.length; i++)
{
if (format.indexOf (strSeparatorAr ray[i]) != -1)
{
sep_char=strSep aratorArray[i];
break;
}
}
tokArr=format.s plit(sep_char);
first_token=tok Arr[0];
second_token=to kArr[1];
third_token=tok Arr[2];
if(sep_char=="" )
sep_char="/";
len1=first_toke n.length;
len2=second_tok en.length;
var currtemp = (window.Event) ? e.which : e.keyCode;
currkey=String. fromCharCode(cu rrtemp);
//if(length<forma t.length)
{
if(!isNaN(currk ey) && e.keyCode!=32 && e.keyCode!=13 && e.which!=32)
{
if(length<len1)
{
switch(first_to ken.toUpperCase ())
{
case 'DD':
if(length==0)
{
if(currkey=='0' || currkey=='1' || currkey=='2' || currkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==1)
{
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1' || string=='2')
objName.value+= currkey+sep_cha r;
if(string=='3' && (currkey=='0' || currkey=='1'))
objName.value+= currkey+sep_cha r;
}
break;
case 'MM':
if(length==0)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
t_flag1=false;
}
if(length==1)
{
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
else
if(string=='1' && (currkey=='0'|| currkey=='1'||c urrkey=='2'))
objName.value+= currkey+sep_cha r;
}
break;
case 'YY':
if(length==0)
objName.value+= currkey;
if(length==1)
objName.value+= currkey+sep_cha r;
break;
case 'YYYY':
if(length==0 && currkey!=0)
objName.value+= currkey;
if(length==1 || length==2)
objName.value+= currkey;
if(length==3)
objName.value+= currkey+sep_cha r;
break;
}
}
else
{
if(length>len1 && length<=len1+le n2)
{
switch(second_t oken.toUpperCas e())
{
case 'DD':
if(length==3)
{
if(currkey=='0' ||currkey=='1'| |currkey=='2'|| currk ey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==4)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1'| |string=='2')
objName.value+= currkey+sep_cha r;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey+sep_cha r;
}
if(length==5)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==6)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
if(string=='1'| |string=='2')
objName.value+= currkey+sep_cha r;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey+sep_cha r;
}
break;
case 'MM':
if(length==3)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==4)
{
string=string.s ubstring(string .length-1);
if(string=='0')
objName.value+= currkey+sep_cha r;
if(string=='1'& &(currkey==' 0' || currkey=='1' || currkey=='2' ))
objName.value+= currkey+sep_cha r;
}
if(length==5)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey+sep _char;
}
if(length==6)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey+sep_cha r;
else
if(string=='1' &&(currkey== '0' || currkey=='1' || currkey=='2'))
objName.value+= currkey+sep_cha r;
}
break;
}
}
else
{
switch(third_to ken.toUpperCase ())
{
case 'DD':
if(length==6)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
}
if(length==7)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1'| |string=='2')
objName.value+= currkey;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey;
}
if(length==8)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
objName.value+= currkey;
else
objName.value+= "0"+currkey
}
if(length==9)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1'| |string=='2')
objName.value+= currkey;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
objName.value+= currkey;
}
break;
case 'MM':
if(length==6)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
t_flag3=false;
}
if(length==7)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1' &&(currkey== '1' || currkey=='2' || currkey=='0'))
objName.value+= currkey;
}
if(length==8)
{
if(currkey=='0' ||currkey=='1')
objName.value+= currkey;
else
objName.value+= "0"+currkey ;
}
if(length==9)
{
string=string.s ubstring(string .length-1);
if(string=='0' && currkey!='0')
objName.value+= currkey;
if(string=='1' &&(currkey== '1' || currkey=='2' || currkey=='0'))
objName.value+= currkey;
}
break;
case 'YY':
if(length==6 || length==7)
objName.value+= currkey;
break;
case 'YYYY':
if(length==6 &&currkey!=' 0')
objName.value+= currkey;
if(length==7 || length==8 || length==9)
objName.value+= currkey;
break;
}
}
}
}// end of currkey if
}//end of format length if
if(e.keyCode==8 || e.keyCode==37 || e.keyCode==39)
return true;
if(window.event )
window.event.ke yCode=13;
else
return false;
}// 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]Comment
-
Originally posted by sunita jadhavmy question is if i type in html textbox on key press event suppose i type 12/03/2008 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i have face problem that is if i insert 6 at 3 this value is not insert at 3 it insert last positon i.e after last value .In given example the value is appned or insert after 5 then output is 12/0/20006 but i have want the output 12/06/2008 and i also give the maxlength to textbox. so plz help me
I give you a code with which you can understand how the date value can be used:
[HTML]<Html>
<head>
<script language="javas cript">
function changeVal(month )
{
if(month=="jan" ||month=="Jan"| |month=="JAN")
month=0;
if(month=="feb" ||month=="Feb"| |month=="FEB")
month=1;
if(month=="mar" ||month=="Mar"| |month=="MAR")
month=2;
if(month=="apr" ||month=="Apr"| |month=="APR")
month=3;
if(month=="may" ||month=="May"| |month=="MAY")
month=4;
if(month=="jun" ||month=="Jun"| |month=="JUN")
month=5;
if(month=="jul" ||month=="Jul"| |month=="JUL")
month=6;
if(month=="aug" ||month=="Aug"| |month=="AUG")
month=7;
if(month=="sep" ||month=="Sep"| |month=="SEP")
month=8;
if(month=="oct" ||month=="Oct"| |month=="OCT")
month=9;
if(month=="nov" ||month=="Nov"| |month=="NOV")
month=10;
if(month=="dec" ||month=="Dec"| |month=="DEC")
month=11;
return(month);
}
function findDiff()
{
var day1, day2;
var month1, month2;
var year1, year2;
value1 = document.getEle mentById('stDat e').value;
value2 = document.getEle mentById('endDa te').value;
day1 = value1.substrin g (0, value1.indexOf ("-"));
month1 = value1.substrin g (value1.indexOf ("-")+1, value1.lastInde xOf ("-"));
month1 = changeVal(month 1);
year1 = value1.substrin g (value1.lastInd exOf ("-")+1, value1.length);
day2 = value2.substrin g (0, value2.indexOf ("-"));
month2 = value2.substrin g (value2.indexOf ("-")+1, value2.lastInde xOf ("-"));
month2 = changeVal(month 2);
year2 = value2.substrin g (value2.lastInd exOf ("-")+1, value2.length);
var startDate = new Date(year1,mont h1,day1);
var endDate = new Date(year2,mont h2,day2);
var wrkdays=0;
while(startDate .getTime()<=end Date.getTime())
{
wrkdays++;
if(startDate.ge tDay()==0)
{
wrkdays--;
}
else if(startDate.ge tDay()==6)
{
wrkdays--;
}
else
{
}
var d = new Date(startDate. getTime() + 86400000);
startDate=d;
}
alert("Total Workdays = "+wrkdays);
}
</script>
</head>
<body>
<input type="text" id="stDate"><b r/>
<input type="text" id="endDate"><b r/>
<input type="button" value="calculat e" onclick="findDi ff()">
</body>
</html>[/HTML]
If more doubts please post it surely I can help you out
Regards
Ramanan kalirajan.Comment
-
Hi sunita, this is the second or third time that you've double posted. This is the last time I'll tell you nicely - please do not double post your questions. If you have some more information, post in the same thread.
Also, remember to use [code] tags when posting code.Comment
-
digit insert problem at editing position
hellow frnd following is my code i have some problem in my code.The following code is about date formating in which i type the date in given format i.e mm/dd/yyyy then date is type in given format but if i delete or edit the any digit then after the editing then i can not insert the digit in deleted or edit position.consid er example if i type the date 03/24/2008 then i want to edit or delete the digit 4 and that position i want to insert the 5 but 5 is inserted at last position i.e 03/2/20085 but i want a output like 03/25/2008.I think u understand my problem so plz help me & i want only on keypress event so plz help me.
<----------Code--------------->
[HTML]<html>
<head>
<script type="text/javascript">
[/HTML][CODE=javascript]var len1=0;
var len2=0;
var strSeparatorArr ay=new Array("-","/","!","@","#"," $","%","^","&", "*","_","+","+" ,"|",":","?",". ",","," ","'","~"," ");
function checkdate(t_obj ect,t_event,p_f ormat)
{
var t_val;
var sep_char;
var t_temp;
var first_token;
var second_token;
var third_token;
var cuttofyear=50;
var length = parseInt(t_obje ct.value.length );
var t_format=p_form at;
var token=new Array();
//Get Separator from format string.
strDateformat = t_format;
for (var i= 0; i < strSeparatorArr ay.length; i++)
{
if (strDateformat. indexOf(strSepa ratorArray[i]) != -1)
{
sep_char=strSep aratorArray[i];
break;
}
}
frm1="mm"+sep_c har+"dd"+sep_ch ar+"yyyy";
frm2="dd"+sep_c har+"mm"+sep_ch ar+"yyyy";
frm3="mm"+sep_c har+"dd"+sep_ch ar+"yy";
frm4="dd"+sep_c har+"mm"+sep_ch ar+"yy";
frm5="yyyy"+sep _char+"mm"+sep_ char+"dd";
frm6="yyyy"+sep _char+"dd"+sep_ char+"mm";
frm7="yy"+sep_c har+"mm"+sep_ch ar+"dd";
frm8="yy"+sep_c har+"dd"+sep_ch ar+"mm";
//Get Separator from format string.
str_format=t_fo rmat.toUpperCas e();
token1=str_form at.indexOf("MM" );
token2=str_form at.indexOf("DD" );
token3=str_form at.indexOf("YYY Y");
tok3=str_format .indexOf("YY");
if(token2==0 ||token2==2 || token2==3 || token2==4 || token2==5 || token2==6 || token2==8)
token[0]=str_format.sub string(token2,t oken2+2);
if(token1==0 || token1==2 ||token1==3 || token1==4 || token1==5 || token1==6 || token1==8)
token[1]=str_format.sub string(token1,t oken1+2);
if(token3==0 || token3==4 ||token3==6 || tok3==0 || tok3==4 || tok3==6)
{
if(token3==0 || token3==6 || token3==4)
{
t_val=token3;
while(str_forma t.charAt(t_val) =="Y")
t_val++;
}
if(tok3==0 || tok3==6 || tok3==4)
{
t_val=tok3;
while(str_forma t.charAt(t_val) =="Y")
t_val++;
}
token[2]=str_format.sub string(tok3,t_v al);
}
if(t_format.toU pperCase() ==frm1.toUpperC ase() || t_format.toUppe rCase()==frm3.t oUpperCase())
{
first_token=tok en[1];
second_token=to ken[0];
third_token=tok en[2];
}
if(t_format.toU pperCase() ==frm2.toUpperC ase() || t_format.toUppe rCase()==frm4.t oUpperCase())
{
first_token=tok en[0];
second_token=to ken[1];
third_token=tok en[2];
}
if(t_format.toU pperCase() ==frm5.toUpperC ase() || t_format.toUppe rCase()==frm7.t oUpperCase())
{
first_token=tok en[2];
second_token=to ken[1];
third_token=tok en[0];
}
if(t_format.toU pperCase() ==frm6.toUpperC ase() || t_format.toUppe rCase()==frm8.t oUpperCase())
{
first_token=tok en[2];
second_token=to ken[0];
third_token=tok en[1];
}
if(sep_char=="" )
sep_char="/";
if(first_token= ='YY')
len1=4;
else
len1=first_toke n.length;
len2=second_tok en.length;
var currtemp =(t_event.keyCo de)?t_event.key Code:t_event.wh ich;
var currkey=String. fromCharCode(cu rrtemp);
[/code][code=javascript]
if(!isNaN(currk ey) && t_event.keyCode !=32 && t_event.keyCode !=13 && t_event.which!= 32)
{
if(length<=len1 )
{
switch(first_to ken)
{
case 'DD':
if(length==0)
{
if(currkey=='0' || currkey=='1' || currkey=='2' || currkey=='3')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
}
if(length==1)
{
string=t_object .value.substrin g(0);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
if(string=='1' || string=='2')
t_object.value+ =currkey+sep_ch ar;
if(string=='3' && (currkey=='0' || currkey=='1'))
t_object.value+ =currkey+sep_ch ar;
}
if(length==2)
t_object.value+ =sep_char;
break;
case 'MM':
if(length==0)
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
t_flag1=false;
}
if(length==1)
{
string=t_object .value.substrin g(0);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='1' && (currkey=='0'|| currkey=='1'||c urrkey=='2'))
t_object.value+ =currkey+sep_ch ar;
}
if(length==2)
t_object.value+ =sep_char;
break;
case 'YY':
if(length==0 || length==1)
t_object.value+ =currkey;
year=t_object.v alue;
if(year<cuttofy ear && length==1)
{
t_object.value= "";
t_object.value+ =20+year+sep_ch ar;
}
else
{
if(year>cuttofy ear && length==1)
{
t_object.value= "";
t_object.value+ =19+year+sep_ch ar;
}
}
if(length==4)
t_object.value+ =sep_char;
break;
case 'YYYY':
if(length==0 && currkey!=0 &&(currkey== 1 || currkey==2))
t_object.value+ =currkey;
if(length==1 || length==2)
t_object.value+ =currkey;
if(length==3)
t_object.value+ =currkey+sep_ch ar;
if(length==4)
t_object.value+ =sep_char;
break;
}
}
else
{
if(length>len1 && length<=len1+le n2)
{
switch(second_t oken)
{
case 'DD':
if(length==3)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
}
if(length==4)
{
t_temp=t_object .value.substrin g(0,2);
if(t_temp=='01' || t_temp=='03'|| t_temp=='05'|| t_temp=='07'||t _temp=='08'||t_ temp=='10'||t_t emp=='12')
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
if(string=='1'| |string=='2')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
t_object.value+ =currkey+sep_ch ar;
}
else
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
if(string=='1'| |string=='2')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='3' && currkey=='0')
t_object.value+ =currkey+sep_ch ar;
}
}
if(length==5)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
}
if(length==6)
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
if(string=='1'| |string=='2')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
t_object.value+ =currkey+sep_ch ar;
}
break;
case 'MM':
if(length==3)
{ t_temp=t_object .value.substrin g(0,2);
if(t_temp=='31' )
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
{
if(currkey==3 || currkey==5 || currkey==7 || currkey==8)
t_object.value+ ="0"+currkey+se p_char;
}
}
else
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
}
}
if(length==4)
{
t_temp=t_object .value.substrin g(0,2);
if(t_temp=='31' )
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0' &&(currkey== '1' || currkey=='3' || currkey=='5' || currkey=='7' || currkey=='8'))
t_object.value+ =currkey+sep_ch ar;
else
if(string=='1' &&(currkey== '0' || currkey=='2'))
t_object.value+ =currkey+sep_ch ar;
}
else
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='1' &&(currkey== '0' || currkey=='1' || currkey=='2'))
t_object.value+ =currkey+sep_ch ar;
}
}
if(length==5)
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey+se p_char;
}
if(length==6)
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey+sep_ch ar;
else
if(string=='1' &&(currkey== '0' || currkey=='1' || currkey=='2'))
t_object.value+ =currkey+sep_ch ar;
}
break;
}
}
else
{
switch(third_to ken)
{
case 'DD':
if(length==7)
t_object.value+ =sep_char;
if(length==8)
{
if(currkey=='0' || currkey=='1'|| currkey=='2'||c urrkey=='3')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey
}
if(length==9)
{
t_temp=t_object .value.substrin g(5,7);
if(t_temp=='01' || t_temp=='03'|| t_temp=='05'|| t_temp=='07'||t _temp=='08'||t_ temp=='10'||t_t emp=='12')
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey;
if(string=='1'| |string=='2')
t_object.value+ =currkey;
else
if(string=='3' && (currkey=='0'|| currkey=='1'))
t_object.value+ =currkey;
}
else
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey;
if(string=='1'| |string=='2')
t_object.value+ =currkey;
else
if(string=='3' && currkey=='0')
t_object.value+ =currkey;
}
}
break;
case 'MM':
if(length==7)
t_object.value+ =sep_char;
if(length==8)
{
t_temp=t_object .value.substrin g(5,7);
if(t_temp=='31' )
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
{
if(currkey==3 || currkey==5 || currkey==7 || currkey==8)
t_object.value+ ="0"+currkey ;
}
}
else
{
if(currkey=='0' ||currkey=='1')
t_object.value+ =currkey;
else
t_object.value+ ="0"+currkey ;
}
}
if(length==9)
{
t_temp=t_object .value.substrin g(5,7);
if(t_temp=='31' )
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0' &&(currkey== '1' || currkey=='3' || currkey=='5' || currkey=='7' || currkey=='8'))
t_object.value+ =currkey;
if(string=='1' &&(currkey== '0' || currkey=='2'))
t_object.value+ =currkey;
}
else
{
string=t_object .value.substrin g(t_object.valu e.length-1);
if(string=='0' && currkey!='0')
t_object.value+ =currkey;
if(string=='1' &&(currkey== '1' || currkey=='2' || currkey=='0'))
t_object.value+ =currkey;
}
}
break;
case 'YY':
if(length==5)
t_object.value+ =sep_char;
str=t_object.va lue.substring(0 ,5);
if(length==6 || length==7)
t_object.value+ =currkey;
year=t_object.v alue.substring( 6);
if(year<cuttofy ear && length==7)
{
t_object.value= "";
t_object.value+ =str+sep_char+2 0+year;
}
else
{
if(year>cuttofy ear && length==7)
{
t_object.value= "";
t_object.value+ =str+sep_char+1 9+year;
}
}
break;
case 'YYYY':
if(length==5)
t_object.value+ =sep_char;
if(length==6 &&currkey!=' 0' &&(currkey== 1 || currkey==2))
t_object.value+ =currkey;
if(length==7 || length==8 || length==9)
t_object.value+ =currkey;
break;
}
}
}
}// end of currkey if
if(t_event.keyC ode==8 || t_event.keyCode ==37 || t_event.keyCode ==39)
return true;
if(window.event )
window.event.ke yCode=13;
else
return false;
}// end of checkdate function
[/CODE][HTML]</script>
</head>
<body>
Date Format:<br>
<input type=text id=date_txt name=date_txt onkeypress="ret urn checkdate(this, event,'mm/dd/yyyy')" maxlength=10/>
</body>
</html>[/HTML]Comment
-
sunita, your continuous disregard for the posting guidelines will not be tolerated. You've been told many times to stop double posting your questions (posting the same question again in a new thread). You also never use [code] tags after being asked to do so more than once. Consider this as a last and final warning. The next time could result in a (temp.) ban.
Moderator.Comment
-
hellow frnd i read ur reply & ur code but i want a dateformating using onkeypress event so plz help me .I give the example of my problem suppose i type the date in textbox as 03/26/2008 first is month then date then year if suppose i want to change the 6 and enter 7 at that position then i get the output like 03/2/20087 means 7 is enter at last position but i want to output like 03/27/2008 i was send my code three times so plz help me.It's urgent for me.
Thanking You.Comment
-
I've understood your problem, but your code is far too complicated for such a simple problem. What I suggest is that you either use three fields, then you only need to check for integers, or use regular expressions to check the current input.
Is it possible that you can use three fields for this? If so, you can just use select drop-down elements instead, thus making validation even easier.Comment
Comment