Is there any way I can enable drop down boxes to retain their selection after the user hits the submit button? Currently it retains information entered to text boxes, however I am unable to apply this to both my select boxes and my radio buttons.
Here is my html code for the select box:
<strong>Select Party Size* :</strong>
<select name="party" value="<?php echo $party;?>">
<option value="">Please Select</option>
<option value="5">1 Person (£5)</option>
<option value="10">2 People (£10)</option>
<option value="15">3 People (£15)</option>
<option value="20">4 People (£20)</option>
<option value="25">5 People (£25)</option>
<option value="30">6 People (£30)</option>
<option value="35">7 People (£35)</option>
<option value="40">8 People (£40)</option>
<option value="45">9 People (£45)</option>
<option value="50">10+ People (£50)</option>
</select>
<span id="partySize" class="error"><?php echo $partyErr;?></span>
Here is the php for said select box:
if($_POST['party']=="") {
$partyErr = "Please select the party size";
} else {
$party = test_input($_POST["party"]);
}
Here is also my radio buttons which I would like to apply this to:
html:
<strong> VIP area* : </strong> <br><br> Yes (+£5) <input type="radio" name="vip" value="yes">
<?php if (isset($vip) && $vip=="yes");?>
<br><span id="vip" class="error"><?php echo $vipErr;?></span><br>
No <input type="radio" name="vip" value="no">
<?php if (isset($vip) && $vip=="no");?>
php:
if (empty($_POST["vip"])) {
$vipErr = "Please make a VIP area selection";
} else {
$vip = test_input($_POST["vip"]);
}
The problem is with your HTML. The select
tag does not have a value
attribute, you need to set selected
on the appropriate option
element. Similarly radio buttons use the attribute checked="checked"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.