Page 1 of 1

Dealing with get elements

Posted: Sat Nov 17, 2012 8:45 pm
by pHp_n0ob
Just like in php

Code: Select all

if($_GET['d']==2)
$top="game";
elseif($_GET['d']==3)
$top="app";
else
$top="empty";
echo $top;
is their any way to deal with get variables using javascript only

Re: Dealing with get elements

Posted: Sat Nov 17, 2012 9:25 pm
by requinix
Without a framework, you can run a regex against document.location.search.

Code: Select all

/(&|\?)([^&=]+)=?([^&]*)/g
Take note of how to get multiple results from exec().

Re: Dealing with get elements

Posted: Sun Nov 18, 2012 5:05 am
by pHp_n0ob
Suppose I've a php script

Code: Select all

if($_GET['d']==2)
$top="game";
elseif($_GET['d']==3)
$top="app";
else
$top="empty";
echo $top;
and now I want a script which does the same work but in JavaScript.Is it possible?
requinix wrote:Without a framework, you can run a regex against document.location.search.

Code: Select all

/(&|\?)([^&=]+)=?([^&]*)/g
Take note of how to get multiple results from exec().
Thanx and sorry,because I couldnot understand that because I'm on level 1 now in programming and I think its more than level 5,isn't it,eh?