...

View Full Version : selectedIndex is undefined



gilgalbiblewhee
01-28-2009, 06:48 PM
I'm getting:

Error: bobj.selectedIndex is undefined
Source File: http:.../js/passage.js
Line: 36
I don't know what's wrong with this:


<select id="book" size="5" onchange="fillChapters();" style="border: medium none ; margin: 5px 5px 0px; float: left; background-color: white; width: 190px;">
<option value="" style="background-color: rgb(181, 162, 111); color: white; font-weight: bold; font-style: italic;">Select Book</option>
<option value="1">Genesis</option>
<option value="2">Exodus</option>
<option value="3">Leviticus</option>
<option value="4">Numbers</option>
<option value="5">Deuteronomy</option>
...
</select>


function fillChapters(){
var req = createRequest();
if(req){
req.onreadystatechange = function(){
var c = document.getElementById('showchapterdiv');
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
c.innerHTML = req.responseText;
}
}
}
}
var bobj = document.getElementById('book');
var book = bobj.options[bobj.selectedIndex].value;

req.open('GET','getChapters.php?book='+book,true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}

Philip M
01-28-2009, 07:02 PM
var bobj = document.getElementById('book');
var book = bobj.value;

but it is not a good idea to use the same name book for both a Javascript variable and an HTML element.


"When I was a kid I used to pray every night for a new bike. Then I realised that The Lord doesn't work that way, so I stole one and asked him to forgive me."

gilgalbiblewhee
01-28-2009, 10:25 PM
var bobj = document.getElementById('book');
var book = bobj.value;

but it is not a good idea to use the same name book for both a Javascript variable and an HTML element.


"When I was a kid I used to pray every night for a new bike. Then I realised that The Lord doesn't work that way, so I stole one and asked him to forgive me."

You got a point there!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum