broken select solution
| From: | ROBERT MCPEAK | Date: | Wed, 20 Mar 2002 21:43:04 +0000 |
| Subject: | broken select solution | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-89416@lists.php.net to get a copy of this message | ||
got it:
<?php
echo "$display<Br>";
echo "<form>";
echo "<select
name=\"display\">";
echo "<option
value=\"true\"";
if ($display ==
'true'){echo " selected";}
echo ">Display";
echo "<option
value=\"false\"";
if ($display ==
'false'){echo " selected";}
echo ">Don't Display";
echo "</select>";
echo "</form>";
?>
>>> "ROBERT MCPEAK" <RMCPEAK@jhuccp.org> 03/20/02 04:39PM >>>
Still doesn't work. What gives?
>>> "Kevin Stone" <kevin@helpelf.com> 03/20/02 04:31PM >>>
The contents of $display are a string so you must have quotes
aroud it in the comparison statement.
if ($display == 'false') // should work.
Alternatively you could do.
<select name="display">
<option value=0>True
<option value=1>False
</select>
Now the contents of $display is an integer which will can be
interpreted
as a boolean value (true or false). Then you can compare it like you
had.
if ($display == false)
-Kevin
-----Original Message-----
From: ROBERT MCPEAK [mailto:RMCPEAK@jhuccp.org]
Sent: Wednesday, March 20, 2002 2:24 PM
To: php-general@lists.php.net
Subject: [PHP] Fwd: html form select list "selected"
Whoops! Still won't work but that code should read:
echo "<form>";
echo "<select name=\"display\">";
echo "<option value=\"true\"";
if ($display==true){echo "selected";}
echo ">Display";
echo "<option value=\"false\"";
if ($display==false){echo "selected";}
echo "selected>Don't Display";
echo "</select>";
echo "</form>";
>>> ROBERT MCPEAK 03/20/02 04:20PM >>>
I'd like to determine the selected option in a select list based on a
passed variable. The code below won't work, but I can't figure out
why.
Any guesses?
echo "<form>";
echo "<select name=\"display\">";
echo "<option value=\"true\"";
if ($display==false){echo "selected";}
echo ">Display";
echo "<option value=\"false\"";
if ($display==false){echo "selected";}
echo "selected>Don't Display";
echo "</select>";
echo "</form>";
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php