Solved

javascript read querystring id

Posted on 2014-02-10
4
301 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
Comment Utility
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
Comment Utility
0
 
LVL 2

Expert Comment

by:Aijaz Chauhan
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now