how do i get the variable at the end of a URL so i can use it?
script.html?srcPic=001.jpg
HOW i get the 001.jpg?
so can use it as the src image?
I pass the variable to the end ok i think
THANKS,
| SitePoint Sponsor |




how do i get the variable at the end of a URL so i can use it?
script.html?srcPic=001.jpg
HOW i get the 001.jpg?
so can use it as the src image?
I pass the variable to the end ok i think
THANKS,
Here's a relatively lame solution that only works if there's only one variable in the URL query string.
Playing with indexOf() and substring would enable you to handle more than one variable.Code:<SCRIPT LANGUAGE="JavaScript"> <!-- var urlstring = location.href; alert(urlstring); var qrystring = urlstring.substring(urlstring.indexOf("=") + 1, urlstring.length); alert(qrystring); document.write("<IMG SRC='" + qrystring + "'>"); // --> </SCRIPT>
Hope this helps,
--Rich





or eval(this.location.href.split("?")[1])
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
here's a version that would work if there's multiple variables in the query string...
Code:function getQuery(name){ var query = self.location.search; if(query.length > 0){ name = name+"="; var str = query.substring(1); var start = str.indexOf(name); if(start == -1) return null; start += name.length; var end = str.indexOf("&", start); if(end == -1) end = str.length; return unescape(str.substring(start,end)); }else{ return null; } } function getImageTag(src){ return '<img src="'+src+'" />'; } document.write(getImageTag(getQuery("srcPic")));




only one variable! cheers guys![]()
Bookmarks