Solved

DATE INPUT MASK TEXT FIELD MM/DD/YYYY

Posted on 2001-08-29
10
662 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Illegal invocation error when listener added to Event Target 3 27
Basic JavaScript Question 3 38
Message not shown 5 33
Loop and hide/show dropdown option with jQuery 4 22
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now