I have a bunch of drop down lists on a page, with a checkbox beside each one that relates to each one respectively. When a user selects an option from the drop down, the checkbox is automatically checked, if the user unchecks the checkbox, the dropdown list is automatically reset to "select" which is the default option.
What I'm trying to do is have the dropdown list set to the first item if the user checks the checkbox. My attempts at this are failing, is there a problem with the code below?
Expand|Select|Wrap|Line Numbers
- function CheckDropDown(sFieldID,sNumID) {
- if (!document.getElementById(sFieldID).checked) {
- document.getElementById(sNumID).selectedIndex = document.getElementById(sNumID).options[0];
- }
- else {
- document.getElementById(sNumID).selectedIndex = document.getElementById(sNumID).options[1];
- }
- }
However, no matter whether the box is checked or not, it always sets it to index 0, which is fine when the user unchecks the checkbox, but not when the user checks the checkbox. Not sure why it's doing this, it looks like it should work.
Thanks guys.
Sincerely,
Mark