SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Atlanta, Ga
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing a Querystring on to another web page

    Hi,

    When I click a radio button in a certain web page (rather than a text link), I send the user on to another page.

    Further requirements gathering in this project mandates that I pass a querystring on to that page.

    The querystring is already captured and parsed in the host page and assigned to javascript variables and assigned to form fields.

    For reasons of consistancy in Look and Feel, I use a radio button with a label as a link to another page if the user's needs requires them to go there.

    If they do go there, I need to send along that same querystring.

    Here is my button click action javascript:

    Code JavaScript:
    <input type="radio" name="_fid_30" 
    onClick="window.location='webpage.html'" />

    At the end of that 'webpage.html', I wish to append the querystring that already is captured in the host page's URI.

    Here is the javascript wherein I've captured the querystring:

    Code JavaScript:
    <script language="javascript">
    function getQuerystring(key, default_)
    {
      if (default_==null) default_=""; 
      key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
      var qs = regex.exec(window.location.href);
      if(qs == null)
        return default_;
      else
        return qs[1];
    }
    // CAPTURE QUERY STRING VALUES
    var koID_val = getQuerystring('koID');
    var UID_val = getQuerystring('UID');
    var GivenName_val = getQuerystring('GivenName');
    var MiddleInitial_val = getQuerystring('MiddleInitial');
    var SurName_val = getQuerystring('SurName');
    var Title_val = getQuerystring('Title');
    var Email_val = getQuerystring('Email');
    var QS_val = "?koID="+koID_val+"&UID="+UID_val+"&GivenName="+GivenName_val+"&MiddleInitial="+MiddleInitial_val+"&SurName="+SurName_val+"&Title="+Title_val+"&Email="+Email_val
    </script>

    With my last variable, "QS_val", I'm attempting to capture within that variable the querystring only.

    I've attempted to append this value at the end of 'webpage.html', but when I click the radio button, I arrive at the page, but there is no querystring.

    I appreciate any help with passing the querystring on to the next web page when the radio button is clicked.

    Chris

  2. #2
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Atlanta, Ga
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I pull the desired destination URI into a function and call that function upon clicking the radio button, the desired results are achieved.

    This is what I had before:

    Code JavaScript:
    <input type="radio" name="_fid_30" 
    onClick="window.location='webpage.html'" />
    (What's missing in the code above is the attempt to 'append' the querystring to the end of this URI - - it wasn't pretty)

    And this is what I changed the above code to:

    Code JavaScript:
    <input type="radio" name="_fid_30"  
    onClick="gotowebpage();" />
    <script>
    function gotowebpage(){
    window.location ="webpage.html"+"?koID="+koID_val+"&UID="+UID_val+"&GivenName="+GivenName_val+"&MiddleInitial="+MiddleInitial_val+"&SurName="+SurName_val+"&Title="+Title_val+"&Email="+Email_val;
    }
    </script>

    I find this solution far less clunky than what I was 'attempting' to do. In the event of a page change, placing the JavaScript function just below the event that calls it will make maintenance easier.

    Thanks


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
  •