Best way to extract URL parameter?

Posted on 2005-05-01
Medium Priority
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 = window.location.search; //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
  • 2
LVL 53

Accepted Solution

COBOLdinosaur earned 1600 total points
ID: 13906055
<script type="text/javaScript">
   parmarr = new Array;
   valuearr = new Array;
   function readparms()
         Args = location.search.substring(1);
         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

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


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

850 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