It is currently Fri Mar 29, 2024 1:11 am



Reply to topic  [ 2 posts ] 
a handy javascript function for getting GET vars 
Author Message
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 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]

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Thu Jan 18, 2007 7:41 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
I just do this:
Code:
function qs2get(){
   $_GET = new Array;
   var $parameters = location.search.substring(1).split('&');
   for( var $i = 0; $i < $parameters.length; $i++ ) {
      var $pos = $parameters[$i].indexOf('=');
      if ($pos > 0){
         var $key = $parameters[$i].substring(0,$pos);
         var $value = $parameters[$i].substring($pos+1);
         $_GET[$key] = $value;
      }
   }
}

qs2get();
alert($_GET['nipple_clamp']);


JS's handling of cookies and get data is just retarded.


Thu Jan 18, 2007 12:12 pm
Profile YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.