PDA

View Full Version : Issue with a form data html


thevibe
11-28-2009, 10:56 PM
Hi guys,

I am working on a form and I encountered a problem. I started with a basic form that is attach to a server, so the rules are fixed. The data names can't be change. The form is almost working except for 1 part "date of birth".

This is the code from the basic form for the date of birth;

<input type="text" name="txtContactBDay" size=34>

The problem with this is that if someone is writing 12 january 2004 it won't work, but the user won't know it. The data sent really needs to be in this specific format... mm/dd/yyyy (eg. 10/25/1982 (the forward-slash are really important in the data too)).

So I changed the script to have some option boxes for the year the month and the day. I am wondering how can I write the script that at the end the data gathered is in the good format mm/dd/yyyy and is named "txtContactBDay".

Here's an example of how I scripted the option boxes;

<select name="month" id="date" onchange="return wait_for_load(this, event, function() { editor_date_month_change(this, 'birthday_day','birthday_year'); });">
<option value="na">Month</option>
<option value="1">January</option>...

<select name="day">
<option value="na">Day</option>
<option value="1">1</option>...

<select name="year">
<option value="na">Year</option>
<option value="2009">2009</option>...


Thanks guys !

yell0wdart
11-29-2009, 12:03 AM
Might just want to use a quick regular expression validator function on the client. It's not going to work every time, since people can disable JavaScript, but it's better than nothing. Maybe a quick hint could help too. If the textbox had a value of "mm/dd/yyyy" in it initially that could be cleared out on focus, that could help explain things.

Anyway, to get you started with using regex within JavaScript:
http://www.regular-expressions.info/javascript.html


Example regular expression to match mm/dd/yyyy:

^([1-9]|1[0-2])/([1-9]|[12][0-9]|3[01])/\d{4}$