Re: Fwd: html form select list "selected"
| From: | Erik Price | Date: | Wed, 20 Mar 2002 21:54:25 +0000 |
| Subject: | Re: Fwd: html form select list "selected" | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89420@lists.php.net to get a copy of this message | ||
On Wednesday, March 20, 2002, at 04:23 PM, ROBERT MCPEAK wrote:
Whoops! Still won't work but that code should read:First of all, this form doesn't have a method or action attribute -- so I'm not sure which script you intend to call with it, or what HTTP protocol you intend to pass the data with. But assuming it's the POST method and the action is PHP_SELF, and that you are using PHP 4.1.x or greater: // perform a test to see which should be selected if ($_POST['display'] == 'true') { $select_if_true = "selected=\"yes\""; $select_if_false = "selected=\"no\""; } elseif ($_POST['display'] == 'false') { $select_if_true = "selected=\"no\""; $select_if_false = "selected=\"yes\""; } // create the form, including the above-defined variables $form_html = " <form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\"> <select name=\"display\">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>";
<option $select_if_true value=\"true\">Display</option>
<option $select_if_false value=\"false\">Don't Display</option>
</select>
</form>";
// print the form
print $form_html;
HTH
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
pricee@hhbrown.com