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 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question 'undefined' is null or not an object

    Hey...

    I only know very basic JS...and am having a bit of a problem that i hope someone can help me out with. 99% sure its a simple mistake, but not to sure.

    I have the following script on my page used to take a string out of the url...for example contact.html&name=mike ....this JS is supposed to take 'mike' out of the url...

    Code:
    <!--script forces url into form above as a text string, and then discards everything except the name-->
    <script type="text/javascript">
    
    var locate = window.location
    document.staff.member.value = locate
    
    var text = document.staff.member.value
    
    function delineate(str)
    {
    theleft = str.indexOf("=") + 1
    
    return(str.substring(theleft));
    }
    
    </script>
    OKay......I want to be able to go to this page without having to send a vale along the url sometimes. When I do this however, IE declares that the page is loaded but with error on page, specifically:

    Line 74 (theleft = str.indexOf("=") + 1)
    'Undefined' is null or not an object

    Since im a JS noob i dont know what this means and what i would have to do to fix it. Can someone please help me out here? would be much appreiciated! Thanks!

    BTW, this error doesnt come up when you come to this page via sending a value along the url.

  • #2
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    maybe try: var theleft = ...
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    What is the value of str when you call delineate()? location.search?

    Use this more comprehensive parse query string script.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi glenngv....thankyou for the link....very much appreciated.

    But since i totally suck at this, heres the next problem resulting from replacing my old js with your suggested one.

    I have a list of names in a drop down box, and the default name shown depends on the parsed name string (i.e. if name?=mike, then 'Mike Walker' was the default name on the drop down box for that session). With my old code, I just used a bunch of if and else if's...but i dont know how i would adapt it to use this new JS....can someone please help me? The code is below

    Code:
    <script type="text/javascript">
    	var pqs = new ParseQueryString();
                 var zork = pqs.param("name");
    	var john = 'john';
    	var nick = 'nick';
    	var mike = 'mike';
    	var martin = 'martin';
    	var david = 'david';
    	var webmaster = 'webmaster';
    	var renee = 'renee';
    
    	if (zork == john){
    		document.Contact.send_to.value = 2;
    	}
    
    	else if (zork == nick){
    		document.Contact.send_to.value = 3;
    	}
    
    	else if (zork == mike){
    		document.Contact.send_to.value = 5;
    	}
    
    	else if (zork == martin){
    		document.Contact.send_to.value = 7;
    	}
    
    	else if (zork == david){
    		document.Contact.send_to.value = 6;
    	}
    
    	else if (zork == webmaster){
    		document.Contact.send_to.value = 4;
    	}
    
    	else if (zork == renee){
    		document.Contact.send_to.value = 8;
    	}
    	</script>

    I hope someone has a clue and can help me out.

    Edit note: I added "document.write(zork);" to this to see if it was picking up the parsed string...and it does that alright...it just doesnt affect the drop down box in any way
    Last edited by pinkshiro; 05-31-2005 at 02:02 AM.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Try this:
    Code:
    	var pqs = new ParseQueryString();
            var zork = pqs.param("name");
    	var selIndex = -1;
    
    	switch(zork){
    		case "john":      selIndex=2; break;	
    		case "nick":      selIndex=3; break;	
    		case "mike":      selIndex=5; break;	
    		case "martin":    selIndex=7; break;	
    		case "david":     selIndex=6; break;	
    		case "webmaster": selIndex=4; break;	
    		case "renee":     selIndex=8; break;	
    	}
    	document.Contact.send_to.selectedIndex = selIndex;
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi again,

    I put this into my page, and it didnt seem to do anything. I have read up on selectedIndex and it makes sense that it should work...but it isnt working :/ Any ideas why it might not be?

    selIndex btw...is that shorthand for selectedIndex, or its own variable alltogether?

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    selIndex is a user-defined variable. You can name it with anything you want. It will be set to the selectedIndex property of the Option object to set the selected item of the combo box.

    Did you encounter any error message? Can you post the whole page?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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