View Full Version : variables n dropdown menus

04-01-2003, 04:46 PM

I have a dropdown menu which contains certain values (product names). Is it possible to populate my dropdown menu with a variable that has been passed on from another page?


Page 1.php

Here I have a selection of products, with images and descriptions.
User decides to buy product A, which is red color, made from China, qty is 5, clicks on the link. Code for the link is:

header("Location: /secure/payment.php?product=A&color=".$color."&type=".$type);

on my payment.php page I have dropdown menu which displays the various products. Users can add / subtract upto 5 products per order. I want to be able to display product A in the dropdown menu for products as the first product in the order.

Any ideas how I could do this?

Thanx in advance


04-01-2003, 05:06 PM
Now let me get this straight. The items in the dropdown are already pre-existing, however you want the first item in the dropdown to be what the user selected on a previous page?

04-01-2003, 06:36 PM
ok, maybe i didnt explain myself properly - apologies Spookster. The dropdown menu on the payment.php page is already populated with a list of all the products that are on offer.


<select name="products" onChange="MM_jumpMenu('parent',this,0)">
<option selected>Product A</option>
<option selected>Product B</option>
<option selected>Product C</option>
<option selected>Product D</option>
<option selected>Product E</option>
and so on...

On my products.php page I have all the products with their descriptions, range of colors, pics, etc. These products at the moment are for visuals only, user see's the product they want, they go to the payment page and using the dropdown menu they select the right product.

What I want to do is make the visuals into links, so that when a user clicks on the link (this could be the in the form of the product image, description or text), they are taken to the payment.php page, and the product they have chosen appears in the dropdown menu. All the user has to do is type in the qty (optional, default is 1), and click on place order button.

Is this a better explanation, or have I confused you even more?

04-01-2003, 06:42 PM
Ok it still almost sounds like what I previously thought.

The items in the dropdown are already pre-existing, however you want the item the user selected on a previous page to be the item that is selected by default on the payment page?

04-01-2003, 06:48 PM
yes, thats it. I did think that u understand this, but it confused me instead - lol

04-01-2003, 06:59 PM
Ok then that is easy to do. You can pass it via the URL as you have done:


In your payment page you can dynamically write the necessary code to select the appropriate option by default:

$product = $_GET["product"];

<select name="products" onChange="MM_jumpMenu('parent',this,0)">
<option <?php if($product = "yaks") echo "selected"; ?> >yaks</option>
<option <?php if($product = "Product B") echo "selected"; ?>>Product B</option>
<option <?php if($product = "Product C") echo "selected"; ?>>Product C</option>
<option <?php if($product = "Product D") echo "selected"; ?>>Product D</option>
<option <?php if($product = "Product E") echo "selected"; ?>>Product E</option>

04-02-2003, 01:45 PM
Thanx Spookster!