Best way to extract URL parameter?

Posted on 2005-05-01
Last Modified: 2008-01-09
I need to extract a passed parameter (called tid) (via URL) and put it in a hidden field (easy: 'document.frmCorp.misc.value = extracted_url_param_tid;')
But the extraction part can be tricky... since possible URLs could be - and exceptions could arise...


var our_url =; //will put the URL in a variable, we can work with to extract the value of tid=xxxx

What's the best and most widely supported/industry standard procedure for exception?

(Actual code that examples a practical working solution is obviously the best solution...)
I have cooked up a 'home' solution, but and will post it regardlessly later to admire or laugh at, but am looking for professional answer/solution...

Thank you...
Question by:InGearX
    LVL 53

    Accepted Solution

    <script type="text/javaScript">
       parmarr = new Array;
       valuearr = new Array;
       function readparms()
             Args =;
             parmarr = Args.split('&');
                valuearr[i] = parmarr[i].split('=');
                if (valuearr[i][0]=='tid')  return valuearr[i][1];
          return 'your error message';

    LVL 53

    Expert Comment

    Glad  could help.  Thanks for the A. :^)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    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. …
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    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…

    760 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

    13 Experts available now in Live!

    Get 1:1 Help Now