Read parameters from URL

Posted on 2009-04-21
Last Modified: 2012-05-06
I'm new at javascript and from what i understand what i'm trying to do is no easy step at all.  I need a javascript that will read the parameters from the URL so i can write them in my table.  The only way i can see being able to do this is by reading the parameters into variables and then using the document.write(variablename); to display the results.  i'd REALLY appreciate all the help i can get here.

Question by:tekguy2001
    LVL 19

    Expert Comment

    "The only way i can see being able to do this is by reading the parameters into variables and then using the document.write(variablename); to display the results" ... is exactly how you'd go about it. Have you not got some code to show?
    LVL 2

    Accepted Solution

    adapt this to your code and try:

    var theUrl="";

    var urlPart = theUrl.split("?")[1];//the parameters in a url allways follow the question simbol (?)
    var arrparams = urlPart.split("&");//the parameters in a url allways are separated by and &
    for(var i=0; i< arrparams.length;i++){
        var nameAndValue = arrparams[i].split("=");//the params allways are pairs separated by a equals(=);
        var name=nameAndValue [0];
        var value=nameAndValue [1];
        alert("Name= "+name+"\nValue= "+value);

    LVL 2

    Expert Comment

    i forggot to say:
    the url is accesible using location.href

    Good Luck
    LVL 48

    Assisted Solution

    by:Ryan Chong
    You can try function like this:

    <script language="javascript">

    function querystring(name)   // returns a named value from the querystring
    {  //yourpage.html?xyz=123
       var tmp = ( );
       var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
       if ( i >= 0 )
          tmp = tmp.substring( name.length+i+1 );
          i = tmp.indexOf("&");
          return unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));


    then use like:

    <script language="javascript">

    var mypara = querystring("mypara")
    alert("mypara = " + mypara);


    if you got url like this:

    get the idea?

    Author Comment

    AWESOME!!  Both work, so i'm awarding the points to both.  Thanks for the information.  I have another question posted for as much points as this one.  It's a doozy for me too as now i have to display photo's and it's stored in /lot/paramatername/

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    734 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

    22 Experts available now in Live!

    Get 1:1 Help Now