Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple checkbox, checked or not 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a checkbox, result of being checked/unchecked gets posted. How do I do:

If checked .... do this
If unchecked .... do this.

Found plenty of threads but nothing simple as me. Thanks
 
By playing with this form and submitting:

[tt]test_foo.html[/tt]:
Code:
<html><body><form method="POST" action="show_post.php">
<input type="checkbox" name="fred">
<input type="submit"></form></body></html>

to this script:

[tt]show_post.php[/tt]:
Code:
<?php
print '<html><body><pre>';

print_r ($_POST);

print '</pre></body></html>';
?>

you can see the behavior of checkboxes.





Want the best answers? Ask the best questions! TANSTAAFL!
 
Are you (1) trying to do something after the POST or are you (2) trying to do something within the page when it's checked?

1. sleipnir's answer will show you what the value is at the time of POST.
2. You'll need to use javascript.

Mark
 
Many thanks. I am trying to establish values after their posted on. Thanks sleipnir, that showed the status of the checkbox, showed [OP1] => ON when checked. How do I correctly address the control to use its state, is:

if [OP1] => ON then .....?

Thanks


 
Many thanks sleipnir,

By checking for the presence of the element in $_POST?

You were correct, works fine. Well deserved star for getting me passed that one. Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top