Log in

View Full Version : Is it possible to set Initial State of a Checkbox from outside the form page?



Mark__G
01-10-2008, 10:34 PM
Wondering if it was possible to set the initial state of a check box via the url link similar to passing a hidden value, but done outside the form page?

So I have my form page with multiple check box options allowing the user to select one. I also have pages outside the form that I want if they click the url it sets the initial state of one of the check boxes in the form to be selected. Is this possible?

something like this... http://www.site.com/form.html?variable=selected

Thanks.

Medyman
01-11-2008, 06:23 PM
it's possible with PHP


<?php
$selected= $_GET["selected"];
?>

<input type='checkbox' name='apple' <?php if($selected=='apple') { echo "checked"; } ?>/>

<input type='checkbox' name='orange' <?php if($selected=='orange') { echo "checked"; } ?>/>

<input type='checkbox' name='banana' <?php if($selected=='banana') { echo "checked"; } ?>/>


Now, you would have to change the file extention to .php.
The links to each of those options would be:

form.php?selected=apple
form.php?selected=orange
form.php?selected=banana

you get the idea...

Mark__G
01-17-2008, 01:59 AM
Thanks a bunch! The site is already php, so it was a breeze.