User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,999 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,533 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 234 | Replies: 1 | Solved
Reply
Join Date: Apr 2006
Posts: 62
Reputation: Fenerbahce is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Fenerbahce Fenerbahce is offline Offline
Junior Poster in Training

Selectbox

  #1  
Apr 13th, 2008
Hi,
This code works fine but, when i choose "Female" from selectbox, it sets "Male" in the selectbox again. What is the problem?
Thanks


<?php
if (!isset($_POST["sex"])) {
	print "Please start!";
} else if ("Male" == $_POST["sex"]) {
	print "Male !";
} else if ("Female" == $_POST["sex"]) {
	print "Female !";
} else {
	print "Himmm!";
}
?>

<html>
<head></head>
<body>
<form action="result.php" method="post"> 
SEX? <select name="sex"  >
	  <option value="Male">Male</option>
	  <option value="Female">Female</option>
     </select><br>
<input type="submit" value="Send">
</form>
</body>
</html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 24
Reputation: kevindougans is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevindougans kevindougans is offline Offline
Newbie Poster

Re: Selectbox

  #2  
Apr 13th, 2008
There is much cleaner ways to do this but for a quick fix, below should now work as you expect:


<?php
if (!isset($_POST["sex"])) {
print "Please start!";
} else if ("Male" == $_POST["sex"]) {
print "Male !";
$male_checked = " SELECTED";
} else if ("Female" == $_POST["sex"]) {
print "Female !";
$female_checked = " SELECTED";
} else {
print "Himmm!";
}
?>

<html>
<head></head>
<body>
<form action="result.php" method="post">
SEX? <select name="sex" >
<option value="Male" <?php echo $male_checked ?>>Male</option>
<option value="Female" <?php echo $female_checked ?>>Female</option>
</select><br>
<input type="submit" value="Send">
</form>
</body>
</html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:53 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC