Get Parameter Value from URL

Posted on 2006-04-25
Last Modified: 2008-02-01
Hi Experts,

I need to get the value of a parameter in the URL.

I simply want the value of "clear".  How can I get this in Javascript??
Question by:jollykh
    LVL 17

    Accepted Solution

    Hi jollykh,

    It might sound bad but here was the first link off of a google search:

    function getQueryVariable(variable) {
      var query =;
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
      alert('Query Variable ' + variable + ' not found');

    You would do this to get clear

      alert( getQueryVariable("clear") );

    Joe P

    Author Comment

    I saw that but that code doesn't work.  I tested it out and I didn't get back my value.  I just recieved an alert box that said Query Variable clear not found.
    LVL 17

    Expert Comment

    Hi BogoJoker,

    try this.

    function GetParamValue(param)    {
        var url = document.URL;
        var val = url.replace(eval("/.+\?.*"+param+"=([^&]*)/"), "$1");
    <form name="form1" method="post" action="test2.asp">
      <table width="100%"  border="0">
          <td><input type="button" name="Button" value="GetParameter" onClick="GetParamValue('clear')"></td>

    LVL 30

    Expert Comment

    hi jollykh,

    BogoJoker's code should work. can you show us your code?
    LVL 63

    Expert Comment

    My method is this:

    function getParam(theKey){
      var qV ="[?&]"+theKey+"="));
        return unescape((qV[1]+"&").split("&")[0]);

    var clearVal = getParam("clear");


    Author Comment

    I need to apologize to everyone.  I failed to mention that this is happening within a frame.  Everyone's code that I tried worked so I'm going to split the points.  Hope you are ok with this.
    LVL 17

    Expert Comment

    You wanted to split the points but it looks like that wasnt the result =)
    You can reopen the question by posting in Community Support, make sure you tell them this Question is: Q_21827485
    Split Points is a link down at the bottom by the comment text box.  Hope everyone gets their share of the points if you indeed wanted to split the points.

    Joe P

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    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…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now