Solved

javascript read querystring id

Posted on 2014-02-10
4
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
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…

752 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