RE: [PHP] Fwd: html form select list selected
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=0True option value=1False /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:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 2:24 PM To: [EMAIL PROTECTED] 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 selectedDon'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 selectedDon'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
RE: [PHP] Fwd: html form select list selected
Still doesn't work. What gives? Kevin Stone [EMAIL PROTECTED] 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=0True option value=1False /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:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 2:24 PM To: [EMAIL PROTECTED] 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 selectedDon'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 selectedDon'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
Re: [PHP] Fwd: html form select list selected
On Wednesday, March 20, 2002, at 04:23 PM, ROBERT MCPEAK wrote: 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 selectedDon't Display; echo /select; echo /form; 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\ 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 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php