Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    selectedIndex is undefined

    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:
    Code:
    		<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>
    Code:
    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);
      }
    }
    Compare bible texts (and other tools):
    TheWheelofGod

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,147
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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."

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Philip M View Post
    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!
    Compare bible texts (and other tools):
    TheWheelofGod


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •