PDA

View Full Version : Javascript vs PHP, problem with arrays


Chuff
10-03-03, 05:01 AM
I have a PHP class that generates the following (HTML & Javascript)
It is a date entry, with a button "Today" that sets the select fields to the current value.
I use for this an array named "dateclose", and it did not work (the button Today does not set the select fields to current date)

However, if I use 3 variables, named dateclose0, dateclose1 and dateclose2, and I modify the javascript according to this, it works.

How can I have my javascript work, yet using the array dateclose instead of using 3 different variables ?

<!-- Day select -->
<select name="dateclose[0]">
<option value="">day</option>
<option value="01">01</option>
</select>
...
<option value="31">31</option>
<!-- Month select -->
<select name="dateclose[1]">
<option value="">month</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
...
<option value="12">Dec</option>
</select>
<!-- Year select -->
<select name="dateclose[2]">
<option value="">year</option>
<option value="2008">2008</option>
...
<option value="1909">1909</option>
</select>
<!-- Button Today -->
<input type=button name=today value='Today'
onclick="this.form.dateclose[2].selectedIndex = 6;
this.form.dateclose[1].selectedIndex = 10;
this.form.dateclose[0].selectedIndex = 03;">