InvisibleMan
asked on
DATE INPUT MASK TEXT FIELD MM/DD/YYYY
Hello I need to know how to put a input mask so when the user types onkeydown the format comes out __/__/____. I don't want to split the boxes right now because I have alot of validation already for date but the user has to type slashes.
ASKER
I cant have that value in the textbox because I am pulling a value in some cases from the database so value="<%=datep%>"
ASKER
I cant have that value in the textbox because I am pulling a value in some cases from the database so value="<%=datep%>"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
a marsh I can't use 3boxes there is already validation with the box as it is and the users dont want that.
try this:
<SCRIPT>
var i=0
function handleKey(e)
{
chco= (document.layers) ? e.which : event.keyCode;
key = String.fromCharCode(chco)
d=document.forms[0].date
if(d.value.length>=10){
return false
}
ld=d.value.split("")
ld[i]=key
i++
d.value=ld.join("")
if(i==2 || i==5){
ld[i]='/'
i++
d.value=ld.join("")
}
return false
}
</SCRIPT>
<FORM>
<INPUT TYPE="TEXT" NAME="date" ONKEYPRESS="return handleKey()" MAXLENGTH="10">
</FORM>
<SCRIPT>
var i=0
function handleKey(e)
{
chco= (document.layers) ? e.which : event.keyCode;
key = String.fromCharCode(chco)
d=document.forms[0].date
if(d.value.length>=10){
return false
}
ld=d.value.split("")
ld[i]=key
i++
d.value=ld.join("")
if(i==2 || i==5){
ld[i]='/'
i++
d.value=ld.join("")
}
return false
}
</SCRIPT>
<FORM>
<INPUT TYPE="TEXT" NAME="date" ONKEYPRESS="return handleKey()" MAXLENGTH="10">
</FORM>
ASKER
bebonham still is not working it jumbles things up and doesnt even let me type anything most times.
yeah, it'll do that in netscape, it works perfectly in ie though.
this is the best it is going to get unless you use 3 fields...
I suggest you use browser sniffing and use this only for ie..
which is over 80% of all people...
this is the best it is going to get unless you use 3 fields...
I suggest you use browser sniffing and use this only for ie..
which is over 80% of all people...
either that or reject my answer and accept someone elses, but I don't think anything else needs to be said, unless you are having problems with my script in ie, or you decide to use 3 boxes.
InvisibleMan please either:
1. Award the question to an expert
2. Request points refunded for no answer
Do not accept this comment as an answer!
Lunchy
Friendly Neighbourhood Community Support Moderator
1. Award the question to an expert
2. Request points refunded for no answer
Do not accept this comment as an answer!
Lunchy
Friendly Neighbourhood Community Support Moderator
<SCRIPT>
function handleKey(e)
{
chco= (document.layers) ? e.which : event.keyCode;
key = String.fromCharCode(chco)
d=document.forms[0].date
d.value=d.value.replace(/_
}
</SCRIPT>
<FORM>
<INPUT TYPE="TEXT" NAME="date" value="__/__/____" MAXLENGTH="10" ONFOCUS="document.onkeypre
</FORM>