Re: Checkbox query

From: Date: Thu, 15 May 2003 20:42:44 +0000
Subject: Re: Checkbox query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147800@lists.php.net to get a copy of this message
> I am sending some values from a form and am using checkboxes...I have set it > so if the checkbox is checked its value is "1". > How do i set the "unchecked" value? > can i set it in the first place? > If its not checked what is usually the value? Do you read the other emails on this list, too, or just ask questions? Checkboxes were the subject of quite a few posts in recent weeks. If a checkbox is not checked, then the variable is not set at all... So, to do something like you want, use this: if(isset($_POST['checkbox'])) { echo "Checkbox was checked.. values is: {$_POST['checkbox']}"; } else { echo "Checkbox was not checked.. assigning default value..."; $_POST['checkbox'] = 'default value'; } or simply: $cb = (isset($_POST['checkbox'])) ? 1 : 0; $cb will then be 1 or 0 based on whether the box was checked or not. ---John Holmes...

« previous php.general (#147800) next »