help! passing list value using href

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kid
    New Member
    • Jul 2007
    • 13

    help! passing list value using href

    hi guys need help again...

    i need to pass my form values in the browser's address bar using href.

    can anyone help me on how to do this? thanks and God bless.
    Last edited by kid; Aug 24 '07, 09:56 AM. Reason: add few more sentence
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by kid
    hi guys need help again...

    i need to pass my form values in the browser's address bar using href.

    can anyone help me on how to do this? thanks and God bless.
    Hi,

    Set the form method to 'GET' and away you go. This would mean that the information could be seen by on the address bar. It may be better to use 'POST' and then access it at the other side using $_POST[]. If it can't be seen it has to be safer.

    Take a look at form methods, it's fairly straight forward stuff, and you should be up and running in no time.

    Cheers
    nathj

    Comment

    • kid
      New Member
      • Jul 2007
      • 13

      #3
      Originally posted by nathj
      Hi,

      Set the form method to 'GET' and away you go. This would mean that the information could be seen by on the address bar. It may be better to use 'POST' and then access it at the other side using $_POST[]. If it can't be seen it has to be safer.

      Take a look at form methods, it's fairly straight forward stuff, and you should be up and running in no time.

      Cheers
      nathj
      hi! i know how to use that method but my real problem is i want to display the value of my list in the address bar of browser this is my sample code but it is not working.

      <div align='left'>Re gion&nbsp
      <select name='region' id='region'>
      <option value='****' selected>[Select]</option>
      <option value='LUZON'>L uzon</option>
      <option value='VISAYAS' >Visayas</option>
      </select>
      <?
      $a = $_GET['region'];
      ?>


      <a href='page.php? region=$a' >sample</a>

      can you help me on this? please

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Hi,

        Could you post the full code for the form? This may shed some more light on the matter.

        Cheers
        nathj

        Comment

        • kid
          New Member
          • Jul 2007
          • 13

          #5
          Originally posted by nathj
          Hi,

          Could you post the full code for the form? This may shed some more light on the matter.

          Cheers
          nathj


          <form id="all_region " name="all_regio n" method="GET" action="">
          <label>
          <select name="region" id="region">
          <option value="****">[Select]</option>
          <option value="LUZON">L uzon</option>
          <option value="VISAYAS" >Visayas</option>
          </select>
          </label>
          <?
          $a = $_GET["Region"];
          ?>
          <p><a href="page.php? region=<? echo $a ?>">GO</a></p>
          </form>


          this is my code but it is not working i cannot echo $a in my browser.

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #6
            Hi,

            there is nothing to submit your form and the action is empty.

            If you want it to stay on the same page set the action to that page and then add aubmit button to the form.

            At the top of the page you can test for the $_GET[] variableand if it has been set then do whatever needs to be done otherwise display the form.

            The information in the $_GET[] array is not set until the form is submitted. So you need to submit the form in order to set the array.

            Cheers
            nathj

            Comment

            • entertainmentliveuk
              New Member
              • Aug 2007
              • 9

              #7
              Originally posted by kid
              <form id="all_region " name="all_regio n" method="GET" action="">
              <label>
              <select name="region" id="region">
              <option value="****">[Select]</option>
              <option value="LUZON">L uzon</option>
              <option value="VISAYAS" >Visayas</option>
              </select>
              </label>
              <?
              $a = $_GET["Region"];
              ?>
              <p><a href="page.php? region=<? echo $a ?>">GO</a></p>
              </form>


              this is my code but it is not working i cannot echo $a in my browser.
              OK I think what you need is this:
              [PHP]
              <form id="all_region " name="all_regio n" method="GET" action="">
              <label>
              <select name="region" id="region">
              <option value="****">[Select]</option>
              <option value="LUZON">L uzon</option>
              <option value="VISAYAS" >Visayas</option>
              </select>
              </label>
              <?
              if(isset($_REQU EST["region"]))
              {
              $a = $_REQUEST["region"];
              ?>
              <p><a href="page.php? region=<? echo $a ?>">GO</a></p>
              <?
              }
              else
              { ?>
              <input type="submit" value="Update link">
              </form>
              } ?>
              [/PHP]

              I have not tested this, but first you need to submit the information to the same page (action=""), then using the if(isset(bla)) code, capture the submitted 'region' value.

              Comment

              Working...