Re: [PHP] Fwd: html form select list "selected"

2002-03-20 Thread Erik Price


On Wednesday, March 20, 2002, at 04:23  PM, ROBERT MCPEAK wrote:

> Whoops!  Still won't work but that code should read:
>
> echo "";
>   echo "";
>   echo "   if ($display==true){echo "selected";}
>   echo ">Display";
>   echo "   if ($display==false){echo "selected";}
>   echo "selected>Don't Display";
>   echo "";
>   echo "";

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 = "

   
 Display
 Don't Display
   
";

// 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




RE: [PHP] Fwd: html form select list "selected"

2002-03-20 Thread ROBERT MCPEAK


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.


True
False


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 "";
echo "";
echo "Display";
echo "Don't Display";
echo "";
echo "";

>>> 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 "";
echo "";
echo "Display";
echo "Don't Display";
echo "";
echo "";


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"

2002-03-20 Thread Kevin Stone

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.


True
False


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 "";
echo "";
echo "Display";
echo "Don't Display";
echo "";
echo "";

>>> 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 "";
echo "";
echo "Display";
echo "Don't Display";
echo "";
echo "";


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