tleisher Posted September 9, 2006 Share Posted September 9, 2006 Is there anyway to setup an HTML form so that if the box isn't checked it returns no, or false? RIght now if it isn't checked it just returns blank/not set, but if it is checked then it returns "On" I'd like to change this to either be checked = "yes" and unchecked = "no" or just true/false, or even on/off. Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 9, 2006 Share Posted September 9, 2006 It does return false, if you check the value in an if statement and it is unchecked, it will not go into the if statement. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 9, 2006 Share Posted September 9, 2006 copy and past so you understand the concept of if and checkbox.good luck.example fully tested.test.php[code]<?php$like=$_POST['like'];if($like=="yes"){echo "<b>I like redarrow</b>";}elseif($like=="no"){echo "<b> I dont like redarrow </b>";} ?><html><body><form method="POST" action=""><br>do you like redarrow<br><input type="checkbox" name="like" value="yes" >yes<br><input type="checkbox" name="like" value="no" >no<br><br><input type="submit" name="submit" value="ansaw"></form></html></body>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 9, 2006 Share Posted September 9, 2006 If you take redarrow's suggestion, both checklboxes could be checked, but only one value will get passed back to your script. Most likely the value of the last box, "no", but, I believe, that's not guarenteed. If you want to do it this way, use radio buttons, which act like toggle switches.[code]<?phpif (isset($_POST['submit'])) { //only check if the form has been submitted echo 'The answer to the question is ' . $_POST['test'] . "<br>/n";}?><form method="post">Are you awake? Yes: <input type="radio" name="test" value="yes" checked> | No: <input type="radio" name="test" value="no"><br><input type="submit" name="submit" value="Answer the question"></form>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.