Page 1 of 1

Checkbox and list problem

Posted: Sun Feb 07, 2010 8:14 pm
by jack2010
Hi there

I want my form to keep values entered by user after submit form. It works for input text fields but for lists and checkbox it refreshes the selection. I have no idea how lists can rember their selected option.

And this is what i'm doing for Checkbox

if (isset($_POST['cb1']))
{$_SESSION['cb1']= 'Yes';}

<input type="checkbox" name="cb1" value= "<?php echo $_SESSION['cb1']; ?>" onClick="validate();" >

Any help ??

Re: Checkbox and list problem

Posted: Sun Feb 07, 2010 9:10 pm
by manohoo
Jack, for lists the value entered should be in the form:
<OPTION value="x" DEFAULT>$enteredValue</OPTION>
"default" is the key word

for check boxes:
<INPUT TYPE="CHECKBOX" NAME="sendmail" VALUE="send" CHECKED>
"checked" is the key word

Re: Checkbox and list problem

Posted: Mon Feb 08, 2010 2:06 am
by limitdesigns
To expand on that, you would have a php conditional to determine whether you add "checked='checked'" (this is the more valid option, rather than simply CHECKED) to the input tag. Something like...

Code: Select all

 
<input type="checkbox" <?php if(isset($_POST['cb1'])) { echo "checked='checked'";}?> name="cb1" />