Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2009, 05:48 PM   PM User | #1
gilgalbiblewhee
Regular Coder

 
Join Date: Mar 2005
Posts: 735
Thanks: 4
Thanked 1 Time in 1 Post
gilgalbiblewhee is an unknown quantity at this point
selectedIndex is undefined

I'm getting:
Quote:
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
gilgalbiblewhee is offline   Reply With Quote
Old 01-28-2009, 06:02 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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."
Philip M is offline   Reply With Quote
Old 01-28-2009, 09:25 PM   PM User | #3
gilgalbiblewhee
Regular Coder

 
Join Date: Mar 2005
Posts: 735
Thanks: 4
Thanked 1 Time in 1 Post
gilgalbiblewhee is an unknown quantity at this point
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
gilgalbiblewhee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:40 AM.


Advertisement
Log in to turn off these ads.