a handy javascript function for getting GET vars
hey, I found this online somewhere and thought I'd share. I make prolific use of GET vars where it makes sense (you can bookmark a GET, after all), and I make prolific use of javascript for AJAX, but getting a GET var with javascript can be a pain. This function does it for you.
[php]
function gup(name){
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
return "";
else
return results[1];
}
[/php]
just pass it the name of the var you want and it'll send back the value. VERY handy.
[php]
function whatever(){
document.getElementById('PigIsTheCoolest').innerHTML = gup('PigGetVar');
}
[/php]