Solved

javascript read querystring id

Posted on 2014-02-10
4
305 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now