Jump to content

Archived

This topic is now archived and is closed to further replies.

Terry103

Passing a select option via url

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?

Share this post


Link to post
Share on other sites
Question #1: Why don't you want to do it as part of a submit function?

Question #2: Are you trying to send it to the other page without leaving the page you are on?

From what I see so far, it appears that you will have to do it with Javascript.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.