SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple values in query string

    I am currently passing a hard coded value from a HREF Link (i.e. offerpage.html?2G4WS52J411279493) and placing that value into the contents of a form. On the offerpage.html which contains the form, I am picking up the value using this code:

    function getParam() {
    if (!document.f1) return;

    document.f1.vehicleid.value=unescape((''+self.location.search).substring(1));
    }

    getParam();

    I now need to pass two values, the first one to vehicleid and the second one to a form field called askingprice. I can hardcode another value into the HREF link, but how would I pick the second value up in the javascript on the form page?

    Thanks!

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is how I would do it. First your link:
    <A HREF="page.html?12345&6789">Click</A>

    Then in the page you are going to (page.html) you would place this script:
    <SCRIPT LANGUAGE="JavaScript">
    function getParam()
    {
    var passdata=unescape(location.search.substring(1,location.search.length))
    var tdata=passdata.split("&")
    document.f1.vehicleid.value=tdata[0]
    document.f1.askingprice.value=tdata[1]
    }
    getParam()
    </SCRIPT>

    what you do is when you hardcode the two values you would first have the question mark (?) then the first value followed by an ampersand (&) and then the second value. In the next page the first line extracts the two values starting after the question mark. The next line splits the two values apart where it encounters an ampersand which creates an array (tdata). this should do the trick. Post again if you have any problems or questions. Good Luck.


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
  •