View Full Version : Handle check Box

04-23-2004, 07:50 AM
I am sure this must have been answered but I tried to locate but could not get exact answer

1. I am reading a database table
2. Based on its value say $active = "Y"
3. I want to make the check box checked
if $acive="Y" then make the check box checked
keep it unchecked
4. Also pass(to database) "Y" when the check box is checked and "N" otherwise..

Please help !!!

Thanks in advance

04-23-2004, 04:20 PM
if checked the variable $_REQUEST['chk']; will have a value on the receiving page , (check for <?if(!empty($_REQUEST['chk'])){/*etc*/}?>

$CHK = ( $active=='Y' ) ? ' CHECKED' : '' ;
<input type="checkbox" name="chk" value="<?=$active;?>"<?=$CHK;?> />

note that the above HTML is not valid though it will work , I think checked is now an attribute?.