Solved

javascript read querystring id

Posted on 2014-02-10
4
312 Views
Last Modified: 2014-02-11
Just want to some like in the javascript

if request.querystring("id") = 1 then
   show LeftNavLinks1
   hid LeftNavLinks2
elseif  request.querystring("id") = 2 then
   show LeftNavLinks2
  hid LeftNavLinks1
end if

Open in new window


How can I do that in javascript? Thanks

<div id="LeftNavLinks1">  
sxxxx
</div>
<div id="LeftNavLinks2">
sxxx
</div>

Open in new window

0
Comment
Question by:CoolDev2014
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39849100
var querystring = function(str) {
    var r = new RegExp("(&|\\?)" + str + "=([^&]+)");
    return (location.search.match(r)||[null]).pop();
};

var show = function(id) { document.getElementById(id).style.display = "block"; };
var hide = function(id) { document.getElementById(id).style.display = "none"; };

var qs = querystring("id");
if(qs=="1") {
   show("LeftNavLinks1");
   hide("LeftNavLinks2");
}
else if(qs=="2") {
   show("LeftNavLinks2");
   hide("LeftNavLinks1");
}

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39849104
0
 
LVL 2

Expert Comment

by:Aijaz Chauhan
ID: 39849810
Try This

var path = window.location.href;
var val = path.match(/id=(\d+)/);

if (val = = 1)
{
  //Your Code
}
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39849859
var path = "http://www.aijaz-chauhan.com/solution.php?test=123&pid=10&id=20&foo=40";
var val = path.match(/id=(\d+)/); // return 10 !!!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question