SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Script GET and POST

    Help neede....
    i want to read varaible value using java script.
    For ex: url: http://www.test.com/myvar=goon&myvar2=stop

    <script>
    read myvar_value_here
    read myvar2_value_here

    </script>

    please advice.
    thanks

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everyone repeat after me: "Google is my friend!"

    This is one of about a zillion functions for reading GET parameters I found in a Google search:

    Code:
    var qsParm = new Array();
    function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
    var key = parms[i].substring(0,pos);
    var val = parms[i].substring(pos+1);
    qsParm[key] = val;
    }
    }
    }
    http://javascript.about.com/library/blqs1.htm

    Reading POST variables will be a little trickier. You might try using an onsubmit handler in your form to put the POST variables into a cookie. Then use a function on the receiving page to parse the cookie.

  3. #3
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.
    i thought there might be some other way out except reading the complete url ...
    anyways thanks

  4. #4
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you are running php or some other server side script you could do something like this as well:
    <?php?
    $myvar=$_GET['myvar'];
    $myvar2=$_GET['myvar2'];
    echo "<script>";
    echo "var myvar=$myvar";
    echo "var myvar2=$myva2r";
    echo "</script>";
    ?>

    This is how I have retrieved post values in the past. The .js function is nodoubt easier though.

  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I used to convert it into JSON format instead of pure echo back, if only you have simple data structure that you can do as above.


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
  •