Dealing with get elements

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
pHp_n0ob
Forum Commoner
Posts: 35
Joined: Mon Jul 09, 2012 7:30 am
Location: India

Dealing with get elements

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Dealing with get elements

Post 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().
pHp_n0ob
Forum Commoner
Posts: 35
Joined: Mon Jul 09, 2012 7:30 am
Location: India

Re: Dealing with get elements

Post 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?
Post Reply