Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for null objects 1

Status
Not open for further replies.

gregmosu

Programmer
Jul 8, 2002
117
US
I have a function that checks for parameters in the query string, and from there determines which page to open up in a certain frame. The only problem is that if I try to hit the page without having a query string, I get a null pointer exception. I've tried several different methods for checking for a null pointer or empty string, but nothing works. Here is the code that parses the query string...
Code:
function grabUrl(){
   urlQuery=location.href.split("?");
   urlTerms=urlQuery[1].split("&");
   uParam=urlTerms[0];
}
[code]

and here is the error message...
'urlQuery.1 is null or not an object'

Thanks in advance,
Greg
 
split() returns array... check for length
Code:
urlQuery=location.href.split("?");
if (urlQuery.length) > 1
{ ... query string present
}
 
Thanks for the help vongrunt, worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top