...

View Full Version : Automatic / when date is entered



carrera
06-06-2003, 08:27 AM
Does anybody know how to automate the / to separate the month, date and year in a textbox?
Example as i type the month 06, it will insert / afterwards. then i type the day 12 and inserts another / then i type the year

Kor
06-06-2003, 10:15 AM
Maybe this will help you
http://www.merlyn.demon.co.uk/js-dates.htm

arnyinc
06-06-2003, 02:23 PM
For dates, you would be much better off using 3 different text boxes or 3 different dropdown boxes and concatenating them when you're all done.

This code works, assuming the user enters the month and date as 2 character strings (i.e. 01/01/2001 instead of 1/1/2001). You can modify it to allow for 1 character dates, but I think three different boxes is the best solution.

<html>
<head>
<script language="javascript">
function checkLength(my_textbox){
if ((my_textbox.value.length==2) || (my_textbox.value.length==5))
my_textbox.value+="/";
}
</script>
</head>
<body>
<form>
<input type="text" name="datebox" onkeyup="checkLength(this);">
<input type="submit">
</form>
</body>
</html>

ca_redwards
06-06-2003, 02:58 PM
Originally posted by carrera
Does anybody know how to automate the / to separate the month, date and year in a textbox?
Example as i type the month 06, it will insert / afterwards. then i type the day 12 and inserts another / then i type the year

If you want a convenient way for the user to enter a valid date into a textfield, you might be interested in this example (http://www.angelfire.com/ca/redwards/html__.calendar.html#examples). Like a file upload component (a textfield for the local file path, plus a "Browse..." button), this date entry implementation offers a readonly textfield to receive the chosen date (MM/DD/YYYY), and a "Calendar..." button to popup a fully-navigable cross-browser calendar.

Let me know if this is something you can use. I may even be able to help you adapt it to suit your particular application.

:ca_redwards.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum