PDA

View Full Version : Dates in form fields



andyc209
06-02-2009, 10:44 AM
Is there a script i can use to do the following

I have 4 text fields each with different dates in and a drop down select menu with numbers from 1 to 28.

If the user selects 10 from the drop down (months) it automatically changes the dates in the four text fields (date1,date2 etc) to add 10 months to the date that was already in there.

<select name="months" style="width: 100px;">
<option selected="selected" value="18">-- 18 (default) -</option>
<option value="0">-- select --</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
.....etc

<input name="date1" id="date1" type="text" tabindex="12" value="20/01/2009" />
<input name="date2" id="date2" type="text" tabindex="12" value="20/03/2009" />
<input name="date3" id="date3" type="text" tabindex="12" value="20/06/2009" />
<input name="date4" id="date4" type="text" tabindex="12" value="20/09/2009" />

forum_amnesiac
06-03-2009, 01:55 PM
This page has a useful feature that adds months to a date, it also adjusts for the end of a month.

http://lawrence.ecorp.net/inet/samples/js-date-fx.shtml

It should be possible to incorporate this into a function that updates the dates in the 4 text boxes using this type of javascript syntax:


document.getElementById('field1').innerHTML = newdate1;
document.getElementById('field1').value = newdate1;
document.getElementById('field2').innerHTML = newdate2;
document.getElementById('field2').value = newdate2;