View Full Version : Select a text from selectbox
letom
02-23-2013, 01:08 PM
Can any body help for the following simple issue
I have a select box as following
<select name="gender">
<option value="0"> Select </option>
<option value="1"> Male </option>
<option value="2"> Female </option>
</select>
I need php code to check the the selected one is Male
It should be like
if (selected one is Male) {
echo "print";
}
Beverleyh
02-23-2013, 03:22 PM
Something like;
HTML
<form action="process.php" method="post">
<select name="gender">
<option value="0"> Select </option>
<option value="1"> Male </option>
<option value="2"> Female </option>
</select>
<input name="process" type="submit" value="Submit" />
</form>
process.php
$selected = $_POST['gender'];
if ($selected == 0) {
echo 'No gender selected';
} else if ($selected == 1) {
echo 'Male option selected';
} else if ($selected == 2) {
echo 'Female option selected';
}
Because php is run server-side, the form would need to be submitted and actioned on the server before the options can be processed.
If you do not want to submit the form and instead want to perform an action "live" in the browser (eg- you want to populate the next question based on a users previous selection) you're probably looking at "chained selects" using JavaScript. Here's the DD script for that: http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm
letom
02-23-2013, 03:52 PM
@Beverleyh
Once again Thanks fr ur message
May be an Experienced programmer can say what i am looking for :)
If any assistance needed i will post
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.