469,307 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

textfield issue on key press - digit insert problem at editing position

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.
Mar 15 '08 #1
9 2454
gits
5,390 Expert Mod 4TB
hi ...

could you please show the code you are using at the moment? that would help us a lot to understand the problem you have ...

kind regards

PS: please remember to use a meaningful thread-title ...
Mar 15 '08 #2
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 strSeparatorArray=new Array("-","/","","!","@","#","$","%","^","&","*","_","+","|"," :","\",","?",".",","," ","'","~");

function checkdate(objName,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").value;

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

tokArr=format.split(sep_char);
first_token=tokArr[0];
second_token=tokArr[1];
third_token=tokArr[2];

if(sep_char=="")
sep_char="/";

len1=first_token.length;
len2=second_token.length;

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

//if(length<format.length)
{
if(!isNaN(currkey) && e.keyCode!=32 && e.keyCode!=13 && e.which!=32)
{
if(length<len1)
{
switch(first_token.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_char;
if(string=='1' || string=='2')
objName.value+=currkey+sep_char;
if(string=='3' && (currkey=='0' || currkey=='1'))
objName.value+=currkey+sep_char;
}
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_char;
else
if(string=='1' && (currkey=='0'||currkey=='1'||currkey=='2'))
objName.value+=currkey+sep_char;
}

break;

case 'YY':
if(length==0)
objName.value+=currkey;

if(length==1)
objName.value+=currkey+sep_char;
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_char;
break;
}
}
else
{
if(length>len1 && length<=len1+len2)
{
switch(second_token.toUpperCase())
{
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.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
if(string=='1'||string=='2')
objName.value+=currkey+sep_char;
else
if(string=='3' && (currkey=='0'||currkey=='1'))
objName.value+=currkey+sep_char;
}
if(length==5)
{
if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey+sep_char;
}

if(length==6)
{
string=string.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
if(string=='1'||string=='2')
objName.value+=currkey+sep_char;
else
if(string=='3' && (currkey=='0'||currkey=='1'))
objName.value+=currkey+sep_char;
}
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.substring(string.length-1);
if(string=='0')
objName.value+=currkey+sep_char;
if(string=='1'&&(currkey=='0' || currkey=='1' || currkey=='2' ))
objName.value+=currkey+sep_char;
}
if(length==5)
{
if(currkey=='0'||currkey=='1')
objName.value+=currkey;
else
objName.value+="0"+currkey+sep_char;
}

if(length==6)
{
string=string.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
else
if(string=='1' &&(currkey=='0' || currkey=='1' || currkey=='2'))
objName.value+=currkey+sep_char;
}
break;


}
}
else
{
switch(third_token.toUpperCase())
{
case 'DD':
if(length==6)
{
if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey;
}
if(length==7)
{
string=string.substring(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'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey
}

if(length==9)
{
string=string.substring(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.substring(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.substring(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.keyCode=13;
else
return false;
}// end of function checkdate
</script>
</head>
<body>
Date :-<br>
<input type=text id=datetext name=datetext onkeypress="checkdate(this,event,'mm/dd/yy')"/>
</body>
</html>[/HTML]
Mar 16 '08 #3
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 strSeparatorArray=new Array("-","/","","!","@","#","$","%","^","&","*","_","+","|"," :","\",","?",".",","," ","'","~");

function checkdate(objName,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").value;

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

tokArr=format.split(sep_char);
first_token=tokArr[0];
second_token=tokArr[1];
third_token=tokArr[2];

if(sep_char=="")
sep_char="/";

len1=first_token.length;
len2=second_token.length;

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

//if(length<format.length)
{
if(!isNaN(currkey) && e.keyCode!=32 && e.keyCode!=13 && e.which!=32)
{
if(length<len1)
{
switch(first_token.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_char;
if(string=='1' || string=='2')
objName.value+=currkey+sep_char;
if(string=='3' && (currkey=='0' || currkey=='1'))
objName.value+=currkey+sep_char;
}
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_char;
else
if(string=='1' && (currkey=='0'||currkey=='1'||currkey=='2'))
objName.value+=currkey+sep_char;
}

break;

case 'YY':
if(length==0)
objName.value+=currkey;

if(length==1)
objName.value+=currkey+sep_char;
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_char;
break;
}
}
else
{
if(length>len1 && length<=len1+len2)
{
switch(second_token.toUpperCase())
{
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.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
if(string=='1'||string=='2')
objName.value+=currkey+sep_char;
else
if(string=='3' && (currkey=='0'||currkey=='1'))
objName.value+=currkey+sep_char;
}
if(length==5)
{
if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey+sep_char;
}

if(length==6)
{
string=string.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
if(string=='1'||string=='2')
objName.value+=currkey+sep_char;
else
if(string=='3' && (currkey=='0'||currkey=='1'))
objName.value+=currkey+sep_char;
}
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.substring(string.length-1);
if(string=='0')
objName.value+=currkey+sep_char;
if(string=='1'&&(currkey=='0' || currkey=='1' || currkey=='2' ))
objName.value+=currkey+sep_char;
}
if(length==5)
{
if(currkey=='0'||currkey=='1')
objName.value+=currkey;
else
objName.value+="0"+currkey+sep_char;
}

if(length==6)
{
string=string.substring(string.length-1);
if(string=='0' && currkey!='0')
objName.value+=currkey+sep_char;
else
if(string=='1' &&(currkey=='0' || currkey=='1' || currkey=='2'))
objName.value+=currkey+sep_char;
}
break;


}
}
else
{
switch(third_token.toUpperCase())
{
case 'DD':
if(length==6)
{
if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey;
}
if(length==7)
{
string=string.substring(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'||currkey=='3')
objName.value+=currkey;
else
objName.value+="0"+currkey
}

if(length==9)
{
string=string.substring(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.substring(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.substring(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.keyCode=13;
else
return false;
}// 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 17 '08 #4
RamananKalirajan
607 512MB
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
Hello Friend I can get your question but inorder to run the code, what you had given it needs the calendar. probably the error may be the with the event.In the input text field you are passing the date object, one event and dare format. please use the code without event.Instead of writing the validation code in onKeyPress write the function in onBlur event. That may be helpful for you.

I give you a code with which you can understand how the date value can be used:

[HTML]<Html>
<head>
<script language="javascript">
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.getElementById('stDate').value;
value2 = document.getElementById('endDate').value;

day1 = value1.substring (0, value1.indexOf ("-"));
month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
month1 = changeVal(month1);
year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

day2 = value2.substring (0, value2.indexOf ("-"));
month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
month2 = changeVal(month2);
year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);

var startDate = new Date(year1,month1,day1);
var endDate = new Date(year2,month2,day2);
var wrkdays=0;

while(startDate.getTime()<=endDate.getTime())
{
wrkdays++;
if(startDate.getDay()==0)
{
wrkdays--;
}
else if(startDate.getDay()==6)
{
wrkdays--;
}
else
{
}
var d = new Date(startDate.getTime() + 86400000);
startDate=d;
}
alert("Total Workdays = "+wrkdays);
}

</script>
</head>
<body>
<input type="text" id="stDate"><br/>
<input type="text" id="endDate"><br/>
<input type="button" value="calculate" onclick="findDiff()">
</body>
</html>[/HTML]

If more doubts please post it surely I can help you out
Regards
Ramanan kalirajan.
Mar 17 '08 #5
acoder
16,027 Expert Mod 8TB
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.
Mar 17 '08 #6
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.consider 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]
Expand|Select|Wrap|Line Numbers
  1. var len1=0;
  2. var len2=0;
  3. var strSeparatorArray=new Array("-","/","!","@","#","$","%","^","&","*","_","+","+","|",":","?",".",","," ","'","~","");
  4. function checkdate(t_object,t_event,p_format)
  5. {
  6.     var t_val;
  7.     var sep_char;
  8.     var t_temp;
  9.     var first_token;
  10.     var second_token;
  11.     var third_token;
  12.     var cuttofyear=50;
  13.     var length = parseInt(t_object.value.length);
  14.     var t_format=p_format;
  15.     var token=new Array();
  16.  
  17.     //Get Separator from format string.
  18.     strDateformat = t_format;
  19.     for (var i= 0; i < strSeparatorArray.length; i++) 
  20.     {    
  21.         if (strDateformat.indexOf(strSeparatorArray[i]) != -1)
  22.         {
  23.             sep_char=strSeparatorArray[i];
  24.             break;
  25.         }
  26.     }
  27.  
  28.     frm1="mm"+sep_char+"dd"+sep_char+"yyyy";
  29.     frm2="dd"+sep_char+"mm"+sep_char+"yyyy"; 
  30.     frm3="mm"+sep_char+"dd"+sep_char+"yy"; 
  31.     frm4="dd"+sep_char+"mm"+sep_char+"yy"; 
  32.     frm5="yyyy"+sep_char+"mm"+sep_char+"dd"; 
  33.     frm6="yyyy"+sep_char+"dd"+sep_char+"mm"; 
  34.     frm7="yy"+sep_char+"mm"+sep_char+"dd"; 
  35.     frm8="yy"+sep_char+"dd"+sep_char+"mm"; 
  36.  
  37.     //Get Separator from format string.
  38.     str_format=t_format.toUpperCase();
  39.     token1=str_format.indexOf("MM");
  40.     token2=str_format.indexOf("DD");
  41.     token3=str_format.indexOf("YYYY");
  42.     tok3=str_format.indexOf("YY");
  43.  
  44.     if(token2==0 ||token2==2 || token2==3 || token2==4 || token2==5 || token2==6 || token2==8)
  45.     token[0]=str_format.substring(token2,token2+2);
  46.     if(token1==0 || token1==2 ||token1==3 || token1==4 || token1==5 || token1==6 || token1==8)
  47.     token[1]=str_format.substring(token1,token1+2);
  48.     if(token3==0 || token3==4 ||token3==6 || tok3==0 || tok3==4 || tok3==6)    
  49.     {    
  50.         if(token3==0 || token3==6 || token3==4)
  51.         {
  52.             t_val=token3;
  53.             while(str_format.charAt(t_val)=="Y")
  54.             t_val++;
  55.         }
  56.         if(tok3==0 || tok3==6 || tok3==4)
  57.         {
  58.             t_val=tok3;
  59.             while(str_format.charAt(t_val)=="Y")
  60.             t_val++;
  61.         }
  62.         token[2]=str_format.substring(tok3,t_val);
  63.     }
  64.  
  65.     if(t_format.toUpperCase() ==frm1.toUpperCase() || t_format.toUpperCase()==frm3.toUpperCase())
  66.     {    
  67.         first_token=token[1];
  68.         second_token=token[0];
  69.         third_token=token[2];
  70.     }
  71.     if(t_format.toUpperCase() ==frm2.toUpperCase() || t_format.toUpperCase()==frm4.toUpperCase())
  72.     {
  73.         first_token=token[0];
  74.         second_token=token[1];
  75.         third_token=token[2];
  76.     }
  77.     if(t_format.toUpperCase() ==frm5.toUpperCase() || t_format.toUpperCase()==frm7.toUpperCase())
  78.     {
  79.         first_token=token[2];
  80.         second_token=token[1];
  81.         third_token=token[0];
  82.     }
  83.     if(t_format.toUpperCase() ==frm6.toUpperCase() || t_format.toUpperCase()==frm8.toUpperCase())
  84.     {
  85.         first_token=token[2];
  86.         second_token=token[0];
  87.         third_token=token[1];
  88.     }    
  89.  
  90.     if(sep_char=="")
  91.     sep_char="/";
  92.  
  93.     if(first_token=='YY')
  94.     len1=4;
  95.     else
  96.     len1=first_token.length;
  97.     len2=second_token.length;
  98.  
  99.     var currtemp =(t_event.keyCode)?t_event.keyCode:t_event.which; 
  100.     var currkey=String.fromCharCode(currtemp);
  101.  
Expand|Select|Wrap|Line Numbers
  1. if(!isNaN(currkey) && t_event.keyCode!=32 && t_event.keyCode!=13 && t_event.which!=32)
  2. {
  3. if(length<=len1)
  4. {    
  5. switch(first_token)
  6. {    
  7.     case 'DD':
  8.          if(length==0)
  9.         {
  10.                                if(currkey=='0' || currkey=='1' || currkey=='2' || currkey=='3')
  11.                        t_object.value+=currkey;
  12.                                  else
  13.             t_object.value+="0"+currkey+sep_char;
  14.  
  15.         }
  16.         if(length==1)
  17.         {
  18.             string=t_object.value.substring(0);
  19.             if(string=='0' && currkey!='0')    
  20.             t_object.value+=currkey+sep_char;    
  21.                           if(string=='1' || string=='2')
  22.                   t_object.value+=currkey+sep_char;
  23.             if(string=='3' && (currkey=='0' || currkey=='1'))
  24.             t_object.value+=currkey+sep_char;
  25.               }
  26.         if(length==2)
  27.         t_object.value+=sep_char;
  28.     break;
  29.  
  30.     case 'MM':
  31.         if(length==0)
  32.         {
  33.                                if(currkey=='0'||currkey=='1')
  34.                        t_object.value+=currkey;
  35.                                  else
  36.             t_object.value+="0"+currkey+sep_char;
  37.             t_flag1=false;
  38.                 }
  39.          if(length==1)
  40.         {
  41.             string=t_object.value.substring(0);
  42.                           if(string=='0' && currkey!='0')
  43.                         t_object.value+=currkey+sep_char; 
  44.               else 
  45.                    if(string=='1' && (currkey=='0'||currkey=='1'||currkey=='2'))
  46.                    t_object.value+=currkey+sep_char;
  47.                    }
  48.         if(length==2)
  49.         t_object.value+=sep_char;
  50.  
  51.     break;
  52.  
  53.     case 'YY':
  54.         if(length==0 || length==1)
  55.         t_object.value+=currkey;
  56.         year=t_object.value;
  57.         if(year<cuttofyear && length==1)
  58.         {
  59.             t_object.value="";
  60.             t_object.value+=20+year+sep_char;
  61.         }
  62.         else
  63.         {
  64.             if(year>cuttofyear && length==1)
  65.             {
  66.                 t_object.value="";
  67.                 t_object.value+=19+year+sep_char;
  68.             }
  69.         }
  70.         if(length==4)
  71.         t_object.value+=sep_char;
  72.  
  73.     break;
  74.  
  75.     case 'YYYY':
  76.         if(length==0 && currkey!=0 &&(currkey==1 || currkey==2))
  77.         t_object.value+=currkey;
  78.         if(length==1 || length==2)
  79.                        t_object.value+=currkey;        
  80.         if(length==3)
  81.                            t_object.value+=currkey+sep_char;
  82.         if(length==4)
  83.         t_object.value+=sep_char;
  84.     break;
  85. }
  86. }
  87. else
  88. {
  89. if(length>len1 && length<=len1+len2)
  90. {    
  91. switch(second_token)
  92. {    
  93.     case 'DD':
  94.         if(length==3)
  95.         {    
  96.             if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
  97.             t_object.value+=currkey;
  98.                             else
  99.             t_object.value+="0"+currkey+sep_char;
  100.         }
  101.         if(length==4)
  102.         {
  103.  
  104.             t_temp=t_object.value.substring(0,2);
  105.             if(t_temp=='01'|| t_temp=='03'|| t_temp=='05'|| t_temp=='07'||t_temp=='08'||t_temp=='10'||t_temp=='12')
  106.             {
  107.             string=t_object.value.substring(t_object.value.length-1);
  108.             if(string=='0' && currkey!='0')
  109.             t_object.value+=currkey+sep_char;
  110.             if(string=='1'||string=='2')
  111.             t_object.value+=currkey+sep_char;
  112.             else 
  113.             if(string=='3' && (currkey=='0'||currkey=='1'))
  114.                                  t_object.value+=currkey+sep_char;
  115.             }
  116.             else
  117.             {
  118.             string=t_object.value.substring(t_object.value.length-1);
  119.             if(string=='0' && currkey!='0')
  120.             t_object.value+=currkey+sep_char;
  121.             if(string=='1'||string=='2')
  122.             t_object.value+=currkey+sep_char;
  123.             else 
  124.             if(string=='3' && currkey=='0')
  125.                                  t_object.value+=currkey+sep_char;
  126.                           }
  127.         }
  128.         if(length==5)
  129.         {    
  130.             if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
  131.             t_object.value+=currkey;
  132.                             else
  133.             t_object.value+="0"+currkey+sep_char;
  134.         }
  135.         if(length==6)
  136.         {
  137.             string=t_object.value.substring(t_object.value.length-1);
  138.             if(string=='0' && currkey!='0')
  139.             t_object.value+=currkey+sep_char;
  140.             if(string=='1'||string=='2')
  141.             t_object.value+=currkey+sep_char;
  142.             else 
  143.             if(string=='3' && (currkey=='0'||currkey=='1'))
  144.                                  t_object.value+=currkey+sep_char;
  145.                       }
  146.     break;
  147.  
  148.     case 'MM':
  149.         if(length==3)
  150.         {    t_temp=t_object.value.substring(0,2);
  151.             if(t_temp=='31')
  152.             {    
  153.                 if(currkey=='0'||currkey=='1')
  154.                            t_object.value+=currkey;
  155.                                      else
  156.                 {
  157.                 if(currkey==3 || currkey==5 || currkey==7 || currkey==8)
  158.                 t_object.value+="0"+currkey+sep_char;
  159.                 }
  160.             }
  161.             else
  162.             {    
  163.             if(currkey=='0'||currkey=='1')
  164.                        t_object.value+=currkey;
  165.                                  else
  166.             t_object.value+="0"+currkey+sep_char;
  167.             }
  168.         }
  169.         if(length==4)
  170.         {
  171.             t_temp=t_object.value.substring(0,2);    
  172.             if(t_temp=='31')
  173.             {
  174.             string=t_object.value.substring(t_object.value.length-1);
  175.             if(string=='0' && currkey!='0' &&(currkey=='1' || currkey=='3' || currkey=='5' || currkey=='7' || currkey=='8'))
  176.                              t_object.value+=currkey+sep_char; 
  177.                    else 
  178.              if(string=='1' &&(currkey=='0' || currkey=='2'))
  179.             t_object.value+=currkey+sep_char;
  180.             }
  181.             else
  182.             {    
  183.             string=t_object.value.substring(t_object.value.length-1);
  184.             if(string=='0' && currkey!='0')
  185.                              t_object.value+=currkey+sep_char; 
  186.                    else 
  187.             if(string=='1' &&(currkey=='0' || currkey=='1' || currkey=='2'))
  188.             t_object.value+=currkey+sep_char;
  189.             }
  190.              }
  191.         if(length==5)
  192.         {    
  193.             if(currkey=='0'||currkey=='1')
  194.                        t_object.value+=currkey;
  195.                                  else
  196.             t_object.value+="0"+currkey+sep_char;
  197.         }
  198.         if(length==6)
  199.         {    
  200.             string=t_object.value.substring(t_object.value.length-1);
  201.             if(string=='0' && currkey!='0')
  202.                              t_object.value+=currkey+sep_char; 
  203.                    else 
  204.             if(string=='1' &&(currkey=='0' || currkey=='1' || currkey=='2'))
  205.             t_object.value+=currkey+sep_char;
  206.              }
  207.     break;
  208. }
  209. }
  210. else
  211. {    
  212. switch(third_token)
  213. {    
  214.     case 'DD':
  215.         if(length==7)
  216.         t_object.value+=sep_char;
  217.         if(length==8)
  218.         {
  219.                                 if(currkey=='0'|| currkey=='1'|| currkey=='2'||currkey=='3')
  220.             t_object.value+=currkey;
  221.                                  else
  222.             t_object.value+="0"+currkey
  223.         }
  224.         if(length==9)
  225.         {    
  226.             t_temp=t_object.value.substring(5,7);
  227.             if(t_temp=='01'|| t_temp=='03'|| t_temp=='05'|| t_temp=='07'||t_temp=='08'||t_temp=='10'||t_temp=='12')
  228.             {
  229.                  string=t_object.value.substring(t_object.value.length-1);
  230.             if(string=='0' && currkey!='0')
  231.             t_object.value+=currkey;
  232.             if(string=='1'||string=='2')
  233.             t_object.value+=currkey;
  234.             else
  235.             if(string=='3' && (currkey=='0'||currkey=='1'))
  236.                                  t_object.value+=currkey;
  237.                           }
  238.             else
  239.             {
  240.             string=t_object.value.substring(t_object.value.length-1);
  241.             if(string=='0' && currkey!='0')
  242.             t_object.value+=currkey;
  243.             if(string=='1'||string=='2')
  244.             t_object.value+=currkey;
  245.             else
  246.             if(string=='3' && currkey=='0')
  247.                                  t_object.value+=currkey;
  248.             }
  249.         }
  250.     break;
  251.  
  252.     case 'MM':
  253.         if(length==7)
  254.         t_object.value+=sep_char;
  255.         if(length==8)
  256.         {
  257.             t_temp=t_object.value.substring(5,7);
  258.             if(t_temp=='31')
  259.             {    
  260.                 if(currkey=='0'||currkey=='1')
  261.                            t_object.value+=currkey;
  262.                                      else
  263.                 {
  264.                 if(currkey==3 || currkey==5 || currkey==7 || currkey==8)
  265.                 t_object.value+="0"+currkey;
  266.                 }
  267.             }
  268.             else
  269.             {    
  270.             if(currkey=='0'||currkey=='1')
  271.                        t_object.value+=currkey;
  272.                                  else
  273.             t_object.value+="0"+currkey;
  274.             }
  275.         }
  276.         if(length==9)
  277.         {    
  278.             t_temp=t_object.value.substring(5,7);    
  279.             if(t_temp=='31')
  280.             {
  281.             string=t_object.value.substring(t_object.value.length-1);
  282.             if(string=='0' && currkey!='0' &&(currkey=='1' || currkey=='3' || currkey=='5' || currkey=='7' || currkey=='8'))
  283.             t_object.value+=currkey;
  284.             if(string=='1' &&(currkey=='0' || currkey=='2'))
  285.             t_object.value+=currkey;
  286.             }
  287.             else
  288.             {
  289.             string=t_object.value.substring(t_object.value.length-1);
  290.             if(string=='0' && currkey!='0')
  291.             t_object.value+=currkey;
  292.             if(string=='1' &&(currkey=='1' || currkey=='2' || currkey=='0'))
  293.             t_object.value+=currkey;
  294.             }
  295.                       }
  296.     break;
  297.  
  298.     case 'YY':
  299.         if(length==5)
  300.         t_object.value+=sep_char;
  301.         str=t_object.value.substring(0,5);
  302.         if(length==6 || length==7)
  303.         t_object.value+=currkey;
  304.         year=t_object.value.substring(6);
  305.         if(year<cuttofyear && length==7)
  306.         {
  307.             t_object.value="";
  308.             t_object.value+=str+sep_char+20+year;
  309.         }
  310.         else
  311.         {
  312.             if(year>cuttofyear && length==7)
  313.             {
  314.                 t_object.value="";
  315.                 t_object.value+=str+sep_char+19+year;
  316.             }
  317.         }
  318.     break;
  319.  
  320.     case 'YYYY':
  321.             if(length==5)
  322.             t_object.value+=sep_char;    
  323.             if(length==6 &&currkey!='0' &&(currkey==1 || currkey==2))
  324.             t_object.value+=currkey;
  325.             if(length==7 || length==8 || length==9)
  326.             t_object.value+=currkey;
  327.     break;
  328. }
  329. }
  330. }
  331. }// end of currkey if
  332.  
  333. if(t_event.keyCode==8 || t_event.keyCode==37 || t_event.keyCode==39)
  334. return true; 
  335. if(window.event)
  336. window.event.keyCode=13;
  337. else
  338. return false;
  339. }// end of checkdate function
  340.  
[HTML]</script>
</head>
<body>
Date Format:<br>
<input type=text id=date_txt name=date_txt onkeypress="return checkdate(this,event,'mm/dd/yyyy')" maxlength=10/>
</body>
</html>[/HTML]
Mar 25 '08 #7
acoder
16,027 Expert Mod 8TB
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.
Mar 25 '08 #8
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.
Mar 26 '08 #9
acoder
16,027 Expert Mod 8TB
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.
Mar 26 '08 #10

Post your reply

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

Similar topics

6 posts views Thread by Ali Eghtebas | last post: by
13 posts views Thread by Stumped and Confused | last post: by
3 posts views Thread by Cah Sableng | last post: by
1 post views Thread by Scott McNair | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.