Solved

DATE INPUT MASK TEXT FIELD MM/DD/YYYY

Posted on 2001-08-29
10
671 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web experts ! HTML ! Javascript project for medical MRI sharing 24 49
Json Schema 8 32
HTML Anchor Link Problem 3 36
Copying table data to one another 15 31
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 …
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…

837 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