Reputation: 622
I am trying to display info based on what the user selects in drop down box and seems I cant get it working:
Here is what I did:
PHP:
if(isset($_POST['order-type'][0])){
$OrderType = "small format black and white";
}
if(isset($_POST['order-type'][1])){
$OrderType = "small format color";
}
HTML:
<select name="order-type">
<option value="SmallFormatBW">Small Format Black & White</option>
<option value="SmallFormatColor">Small Format Color</option>
</select>
Any help is high appreciated! Thanks,
Upvotes: 0
Views: 2188
Reputation: 675
If you use $_POST['order-type'] as array you must collect array from form. In your case you can try this.
<select name="order-type[]">
<option value="SmallFormatBW">Small Format Black & White</option>
<option value="SmallFormatColor">Small Format Color</option>
</select>
Upvotes: 1
Reputation: 1639
Try this
if (isset($_POST['order-type'])) {
if($_POST['order-type'] == 'SmallFormatBW'){
$OrderType = "small format black and white";
} else if($_POST['order-type'] == 'SmallFormatColor'){
$OrderType = "small format color";
}
}
Upvotes: 0
Reputation: 1635
When you select an option
with the value="SmallFormatBW"
from a select
with name="order-type"
and POST
it to PHP. You will access it in PHP as $_POST['order-type']
carrying the value SmallFormatBW
.
$_POST['order-type'] == 'SmallFormatBW'
That means if you want to test the value, you would do it like this
if(!empty($_POST['order-type']) && ($_POST['order-type'] == 'SmallFormatBW')){
$OrderType = "small format black and white";
}
Upvotes: 0
Reputation: 1
you are missing a '$_GET' in the HTML I think...
look here for more info about submitting info from a PHP page to a HTML page: http://www.w3schools.com/php/php_forms.asp
Upvotes: 0