how to retrieve value from drop down list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tonyledenko
Forum Newbie
Posts: 15
Joined: Thu Sep 11, 2008 4:22 pm

how to retrieve value from drop down list

Post by tonyledenko »

Hello, I was wondering how I could post the value from a drop down menu into my form? Thanks in advance

<select name="radio1" style="font-size:10px;"> <option value="none" selected>
<option value="RAM-B-138">ABLE2 - 05-5300 (3")
<option value="RAM-B-137">ABLE7 - 05-5300 (7")
</select>


<?php if ($radio1=="none")
echo '';
else
echo '<span class="contentred">Radio/Control Head/Switch 1: ', $radio1, '</span><br>
<form name="CartItem" action="https://www.ram-mount.com/RamCart/aCartPutItem.php" method="POST" target="myIFrame">
<input type="hidden" name="part" value="$radio1"><input type="submit" value="Add To Cart">
</form>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to retrieve value from drop down list

Post by requinix »

- $radio1 needs a value. If you don't have one already you need a $radio1=$_POST["radio1"] beforehand.

- The last echo statement uses single quotes. Variables don't get interpolated and you'll see them in the output.
The first time you use $radio1 there is correct: do the same thing with the second time.

- Printing data from a form can be dangerous. Instead of using $radio1 directly use htmlentities($radio1) like

Code: Select all

echo '<span class="contentred">Radio/Control Head/Switch 1: ', htmlentities($radio1), '</span><br>...'
tonyledenko
Forum Newbie
Posts: 15
Joined: Thu Sep 11, 2008 4:22 pm

Re: how to retrieve value from drop down list

Post by tonyledenko »

Im sorry - I would like to value to be posted in the form.

<input type="hidden" name="part" value="$radio1">

Thanks for your help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to retrieve value from drop down list

Post by requinix »

tasairis wrote:- The last echo statement uses single quotes. Variables don't get interpolated and you'll see them in the output.
The first time you use $radio1 there is correct: do the same thing with the second time.
tonyledenko
Forum Newbie
Posts: 15
Joined: Thu Sep 11, 2008 4:22 pm

Re: how to retrieve value from drop down list

Post by tonyledenko »

Thank You!!!!!!!!!!!!!!!!!!!!!!!!!!! It worked.
Post Reply