Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript read querystring id

Posted on 2014-02-10
4
Medium Priority
?
338 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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

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 83

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
Suggested Courses

876 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