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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drop down list dynamic newbie question

Status
Not open for further replies.

tictaclam

Programmer
Jan 8, 2004
47
US
below is my code i eventually want to populate theyear with the values of the year which i will get from asp code. But i am getting errors with the code: options is null or not an object. what am i missing?

Code:
<FORM NAME="search" METHOD=GET ACTION="/KeyAndQuery.asp">
<select name = "querystr" onchange ="populate2()">
<option value = "New">New Developments
<option value = "Main">Maintenances/Enhancements
<option value = "Year"> By Year
</select>
<select name ="theyear">
</select>
</FORM>
<SCRIPT LANGUAGE = 'JAVASCRIPT'>
function populate2()
{  
  var box = document.forms["search"].elements["querystr"];
  var index = box.selectedIndex
  var selection = box.options[index].value;
  if (!selectoin || selection!= "Year") return; 
  /*
     more code to come ...
  */
}
</script>
thanks
 

1. You are running the code before the page has loaded.

2. You are using "index" instead of "selectedIndex".

3. You are assuming that the user has selected an item - if they have not, selectedIndex will be -1, and thus options[-1] will be out-of-bounds, so you need to check for this.

4. You are using "selectoin" instead of "selection".

Hope that's enough to get you started ;o)

Dan
 
i fixed the typo and i checked for the -1 but it's still not working. how can i fix point number 1?
 

Doh - my apologies again.. I was wrong on point number 1, too... I plain didn't see the function wrapper around the code (must need new glasses, I think!).

What is the error you are getting?

Dan
 
it says: object doesn't support this property of method. It goes to the line

var selection = box.options[box.selectedIndex].value;

i printed out the value of box.selectedIndex and it was right it just doesn't seem to want to get the value
 
oops my bad i messed up the error. the error says: options is null or is not an object.
sorry about that it still references the same line
 
well since i really only care if "By Year" is selected i can use the index of that option to check. This does work. It seems weird that it didn't work the other way but thanks for you time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top