Jump to content

Passing a select option via url


Terry103

Recommended Posts

Is there a way to pass the value from a drop-down select box via the url to another page:
I can do it if I use a submit control, but that's not what I need to do.
Here is a bare bones example:

test.php

<head>
<title>Passing Variables</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="test2.php" method="post" >
  <table width="100%" border="1">
    <tr>
      <td width="8%">&nbsp;</td>
      <td width="15%"><select name = 'card'>
          <option>VISA
          <option>MasterCard
          <option>American Express</select></td>
      <td width="77%"><a href="test2.php?<?php echo "card="; echo $card; ?>">Add
        to Card </a><a href="test2.php?<?php echo "card="; echo $card; ?>"></a></td>
    </tr>
  </table>
  </form>
</body>
</html>

test2.php:
<?php
  // create short variable names
  $card = $_POST['card']; ?>
<html>
<head>
<title>Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><?php echo $card; ?>

</body>
</html>

When I click on the 'Add to Cart' text, I can't figure out how to get the value from the 'card' control.
Any help?
Link to comment
Share on other sites

I have a repeat region and a drop-down box on each line. It is populated from a database. When the user clicks on the add 2 cart button, it needs to send to the next page the option selected on that row so it can be saved in the cart data. ( My app is letting the user select a color)

I am leaving the page I am on and opening the cart page. From the posted example, I need the url to contain 'card=VISA'. All I get is 'card=' and then an error stating that $card is an unknown variable.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.