Results 1 to 4 of 4

Thread: how do i parse variables in the URL using javascript

  1. #1
    Join Date
    Apr 2009
    Posts
    24

    how do i parse variables in the URL using javascript

    I can pass the variable to next page. Depending on the choice chosen, i have a function which will execute the URL. Does anyone have a code in javascript function call another function. Please Help....!

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: how do i parse variables in the URL using javascript

    Here is the code in java for you for the same you wanted :

    Code:
    function QueryString(key)
    {
    var value = null;
    for (var i=0;i<QueryString.keys.length;i++)
    {
    if (QueryString.keys[i]==key)
    {
    value = QueryString.values[i];
    break;
    }
    }
    return value;
    }
    QueryString.keys = new Array();
    QueryString.values = new Array();
    
    function QueryString_Parse()
    {
    var query = window.location.search.substring(1);
    var pairs = query.split("&");
    
    for (var i=0;i<pairs.length;i++)
    {
    var pos = pairs[i].indexOf('=');
    if (pos >= 0)
    {
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    QueryString.keys[QueryString.keys.length] = argname;
    QueryString.values[QueryString.values.length] = value;
    }
    }
    }
    QueryString_Parse();

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: how do i parse variables in the URL using javascript

    Normally, you take these variables with a language as PHP or JSP and d 'to act on them. Him and the moments that if you have n 'does not have access to a part of the language or simply need to treat these parameters via JavaScript. Here how.


    Code:
    var searchString = document.location.search;
    
    // strip off the leading '?'
    searchString = searchString.substring(1);
    
    var nvPairs = searchString.split("&");
    
    for (i = 0; i < nvPairs.length; i++)
    {
         var nvPair = nvPairs[i].split("=");
         var name = nvPair[0];
         var value = nvPair[1];
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: how do i parse variables in the URL using javascript

    You want to get the value from the frank parameter so you call the javascript function as follows :

    var frank_param = gup( 'frank' );

Similar Threads

  1. Pass Variables By Reference in Javascript?
    By MAGAR in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 04:11 PM
  2. How to parse XML in J2ME
    By Abigail101 in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 03:39 AM
  3. How to Parse XML in ASP
    By Dwarner in forum Software Development
    Replies: 4
    Last Post: 24-01-2010, 04:27 AM
  4. How to Parse CSV file using PERL
    By Xena in forum Software Development
    Replies: 3
    Last Post: 31-08-2009, 10:38 AM
  5. PHP Parse error: parse error unexpected $ in main.php on line 12
    By ΘN-TH3-ЯΘCKZ in forum Software Development
    Replies: 3
    Last Post: 20-08-2009, 06:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,435,511.33044 seconds with 16 queries