Forum Moderators: open

Message Too Old, No Replies

javascript auto selecting the first option box

javascript auto selecting the first option box

         

zorlu

9:19 am on Feb 21, 2007 (gmt 0)

10+ Year Member



hi,

I am populating option boxes with asp. My problem is that I want the first option button to be selected by default.

the first option button has the value 1, second has value 3, third has value 4

but there are 2 more boxes with same option buttons and they have values 3,4,5

first box has name room1, second box has name room2 and third box is called room3

unfortunately I cannot make all of them start with value 1. this is a reservation form for a hotel. it allows maximum of 3 rooms per reservation and if one room has more than 3 people, it does not display the first option. It displays the second and third.

I amsummarizing the three boxes and the option buttons values.

first:
Name: room1 values 1,3,4

Second:
Name: Room2 Values 3,4

Third:
Name: Room3 Values 4,5

So I want these to be checked by default:
Room1 -1
Room2-3
Room3-4

note that the values are dynamic. Can someone please tell me a way to do it by javascript?

Fotiman

3:30 pm on Feb 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why don't you just do it the correct way and give the first option in each list the selected attribute? For example:


<select name="room1">
<option value="1" selected="selected">1</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="Room2">
<option value="3" selected="selected">3</option>
<option value="4">4</option>
</select>
<select name="Room3">
<option value="4" selected="selected">4</option>
<option value="5">5</option>
</select>