PDA

View Full Version : Check box



Moh
22-06-2008, 05:00 PM
When I use a checkbox which isn't checked, it dosn't post it at all.
When its checked, the value is 1, but how do I make it so when its not checked its value is 0?

Independent
22-06-2008, 05:02 PM
When I use a checkbox which isn't checked, it dosn't post it at all.
When its checked, the value is 1, but how do I make it so when its not checked its value is 0?
Mighty question.

Robbie
22-06-2008, 05:16 PM
You mean like:



<?php
$checkbox = $_POST["checkbox"];
if($checkbox !== "1") {
// do nothing
} else {
echo('You ticked it.');
}
?>

?

Moh
22-06-2008, 05:22 PM
You mean like:



<?php
$checkbox = $_POST["checkbox"];
if($checkbox !== "1") {
// do nothing
} else {
echo('You ticked it.');
}
?>?
Im using:

if(isset($_POST["tos"])) { so if its not posting it, then the event wont work :l

Independent
23-06-2008, 06:37 PM
Im using:

if(isset($_POST["tos"])) { so if its not posting it, then the event wont work :l
Do this:



if(isset($_POST["tos"])) {
echo "You're cool, jeez.";
{
else {
echo "You killed it, jeez.";
exit();
}

:D..

Otherwise try some javascript

WhatYouSay
23-06-2008, 08:38 PM
I think that's controlled by the browser, as check-box's were designed for multiple rows, making it more of a "choose-box" (if you buy something from a shop, you would say "I want that", not "I want that one, but not that one, and not that one, and not that one...".

To make the value "0", you can use something like:


<?php
$input=$_POST['tos'];

if (empty($input))
$input=0;

?>

Want to hide these adverts? Register an account for free!