Page 1 of 1
check box IF checked
Posted: Sun Apr 23, 2006 2:24 pm
by wilko18
Anyone know why this really basic IF loop doesn't work?
I just need the code to chenge the value of the variable IF the box is ticked...which it is by default, however the values output is "Not Working" and not "it works".
Code: Select all
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" />
<?php
$price = "not working";
if (isset($_POST['tick1']))
{
$price = "it works";
}
echo $price;
?>
Posted: Sun Apr 23, 2006 2:45 pm
by feyd
Is the form the checkbox apart of use the post method?
Posted: Sun Apr 23, 2006 2:56 pm
by wilko18
I don't quite understand what you mean?
The code I posted is the whole code...we're just trying to get the
if (isset($_POST['tick1']))
to return true...which currently it never does.
Posted: Sun Apr 23, 2006 3:02 pm
by feyd
You have to have a form to submit via post (ignoring Ajax.)
Posted: Sun Apr 23, 2006 3:04 pm
by R4000
page1.php:
Code: Select all
<form action="page2.php" method="POST">
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" />
<input name="submit" type="submit" value="Test!" />
</form>
page2.php:
Code: Select all
<?php
$price = "not working";
if ($_POST['tick1']) {
$price = "it works";
}
echo $price;
?>
Posted: Sun Apr 23, 2006 4:11 pm
by psychotomus
shouldn't
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" /
be checked='true"?
im not an html master. thats why i use an html editor.
Posted: Sun Apr 23, 2006 4:13 pm
by R4000
i dont think it should be either
I'm pretty sure it should be:
Code: Select all
<input type="checkbox" name="NAME" checked />
My bad for not noticing (correct me if im wrong... but im damn sure this is right)
Posted: Sun Apr 23, 2006 4:14 pm
by feyd
What it should be depends on what (X)HTML standard you are following. In HTML 4, just "checked," but in XHTML, 'checked="checked".'