Solved

DATE INPUT MASK TEXT FIELD MM/DD/YYYY

Posted on 2001-08-29
10
676 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:InvisibleMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6437173
fun

<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(/_/,key)
}


</SCRIPT>

<FORM>
<INPUT TYPE="TEXT" NAME="date" value="__/__/____" MAXLENGTH="10" ONFOCUS="document.onkeypress=handleKey" ONBLUR="document.onkeypress=null">
</FORM>
0
 

Author Comment

by:InvisibleMan
ID: 6437450
I cant have that value in the textbox because I am pulling a value in some cases from the database so value="<%=datep%>"
0
 

Author Comment

by:InvisibleMan
ID: 6437452
I cant have that value in the textbox because I am pulling a value in some cases from the database so value="<%=datep%>"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
a.marsh earned 50 total points
ID: 6437667
Whenever I do this I always use three separate textboxes - make it much easier.

And if you are unable to alter any of the server-side scripting that interacts with the database etc., then you should be able to manipulate things with javascript.

I'll put an example together for you.

:o)

Ant
0
 

Author Comment

by:InvisibleMan
ID: 6438540
a marsh I can't use 3boxes there is already validation with the box as it is and the users dont want that.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6438625
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>
0
 

Author Comment

by:InvisibleMan
ID: 6442167
bebonham still is not working it jumbles things up and doesnt even let me type anything most times.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6442439
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...


0
 
LVL 8

Expert Comment

by:bebonham
ID: 6449267
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.
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6648555
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question