Scottie wrote:
David,
What I did was:
var str = window.location.search;
if (str != "") {
var temp = str.split('=');
alert(temp[1]);
What if str.split('=') doesn't create an array, or doesn't create more then one element in the array?
What if there are multiple items being passed on the URL? You'll get both the first value and all the
remaining text from window.location.search.
}
else {
alert("This is NULL");
No, it's not null, because that's not what you're testing str against. Your condition says [if (str !=
"") {], so the else branch of that condition is that (str == ""). In fact, if str is null, it will take
the positive branch (because (null != ""), which will result in an error when you attempt to do
str.split().
}
and it works. Thanks.
Scott
Here is a much better solution:
var s = window.location.search;
// set s for testing
s = 'a=b&c=d&YourAttribute=MyValue&e=f&g=h';
// find the exact value associated with your attribute
(new RegExp('YourAttribute=([^&]+)')).test(s);
if (RegExp.$1) {
alert(RegExp.$1);
} else {
alert('There is no value for "YourAttribute"');
}
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html