get url parameter value in javascript

HI,

I have a URL which has the parameter "ID"

how can i get the value of the ID in javascript

please help

Thanks

R8VI
R8VIAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Big MontyConnect With a Mentor Senior Web Developer / CEO of ExchangeTree.org Commented:
try this:

var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    	// If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
    	// If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;
    	// If third or later entry with this name
    } else {
      query_string[pair[0]].push(pair[1]);
    }
  } 
    return query_string;
} ();

Open in new window

You can then access QueryString.id
0
 
R8VIAuthor Commented:
Hi,

Thanks for this but where do I substitute the ID in your code

R8vi
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
wherever you're looking to use the ID value, such like this:

   var idParam = QueryString.id;

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
R8VIAuthor Commented:
I am sorry could you please explain a bit further
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Ultimately what are you trying to accomplish with the url perameter?
0
 
Sar1973Commented:
Try:
var id = document.getElementById("URL").getAttribute("id");
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
doesn't work in Chrome...
0
 
R8VIAuthor Commented:
Hi,

So I have a URL like so

http://localhost:49768/Solution/IframePage.aspx?Name=Ellis&URL=http://www.test.com

I would like to get the Value of "URL" which in this case would be http://www.test.com
 and store it in a variable

Thanks

R8VI
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
ok, so using my example above, just create a variable:

var myURL;

then assign it like:

myURL = QueryString.URL;

the function I gave earlier runs upon page load, and it basically creates an "object" with properties that are the url parameters
0
 
Sar1973Commented:
You could also toggle the string with JS string functions (see http://w3schools.com/js/js_obj_string.asp) and extract the URL.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.