View Full Version : 'undefined' is null or not an object

05-23-2005, 01:00 AM

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...

<!--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



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.

05-23-2005, 05:38 AM
maybe try: var theleft = ...

05-23-2005, 06:00 AM
What is the value of str when you call delineate()? location.search?

Use this more comprehensive parse query string script (http://www.codingforums.com/showthread.php?t=25786).

05-31-2005, 01:32 AM
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

<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;

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

05-31-2005, 04:55 AM
Try this:

var pqs = new ParseQueryString();
var zork = pqs.param("name");
var selIndex = -1;

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;

06-01-2005, 04:23 AM
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?

06-01-2005, 08:00 AM
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?