Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a dropdown value 1

Status
Not open for further replies.

anto2

Programmer
Apr 4, 2001
29
0
0
IE
Hi,

I have three dropdown select option fields on a html form called myform.

They are hours_values (00 - 23), minutes_values (00 - 59) and day_segment_select (1.00,0.75,0.50,0.25).

when then user changes the day_segment_select the other two dropdowns change depending on values on other fields.

This works when the values change to values other than what they were originally. eg.

hours_values = 08 minutes_values 02 change the day_segment_select and the value changes to hours_values = 10 and minutes_values 10 works. If the user then selects something from the day_segment_select that will cause the values of the other two drop downs to revert to the original values then these list are set to null.

This is the function

function set_hours_minutes()
{
var hours_value
var minutes_value
var segment_value = myform.day_segment_select[myform.day_segment_select.selectedIndex].value;
switch (segment_value)
{
case "1.00":
hours_value = myform.full_day_segment_hours.value;
minutes_value = myform.full_day_segment_minutes.value;
break;
case "0.75":
hours_value = myform.three_quarter_day_segment_hours.value;
minutes_value = myform.three_quarter_day_segment_minutes.value;
break;
case "0.50":
hours_value = myform.half_day_segment_hours.value;
minutes_value = myform.half_day_segment_minutes.value;
break;
case "0.25":
hours_value = myform.quarter_day_segment_hours.value;
minutes_value = myform.quarter_day_segment_minutes.value;
break;
default:
break;
}
alert("hours " + hours_value);
alert("minutes " + minutes_value);
myform.hours_values.value = hours_value;
myform.hours_values.text = hours_value;
myform.minutes_values.value = minutes_value;
myform.minutes_values.text = minutes_value;
}
the alert is bringing back the values I would expect.

Anthony.
 
hi Anthony,

looks like you can use the minutes and hours value to set the selectedIndex since you're starting with zero:

old:
myform.hours_values.value = hours_value;
myform.hours_values.text = hours_value;
myform.minutes_values.value = minutes_value;
myform.minutes_values.text = minutes_value;

new:
myform.hours_values.selectedIndex = hours_value;
myform.minutes_values.selectedIndex = minutes_value;


hope this helps. ======================================

if (!succeed) try();
-jeff
 
Thanks Jeff,

This worked perfectly.

Anthony.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top