?
Solved

Best way to extract URL parameter?

Posted on 2005-05-01
2
Medium Priority
?
1,026 Views
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...

http://localhost/?name=expert&tid=string&db=D5
http://localhost/?name=expert&tid=string
http://localhost/?name=expert
http://localhost/?tid=string

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...
0
Comment
Question by:InGearX
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 1600 total points
ID: 13906055
<script type="text/javaScript">
   parmarr = new Array;
   valuearr = new Array;
   function readparms()
   {
      if(location.search!='')
      {
         Args = location.search.substring(1);
         parmarr = Args.split('&');
         for(i=0;i<parmarr.length;i++)
         {
            valuearr[i] = parmarr[i].split('=');
            if (valuearr[i][0]=='tid')  return valuearr[i][1];
         }
      }
      return 'your error message';
</script>


Cd&
0
 
LVL 53

Expert Comment

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

Cd&
0

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