sseeley Posted June 5, 2009 Share Posted June 5, 2009 I am trying to validate a check box, but my return always just come back with 'on'. Can anyone help me? <head> <script> <!-- function validate() { var deleted=document.getElementById("del").value alert(deleted); } --> </script> </head> <?php echo "<form action=\"test1.php\" method=\"POST\" name=\"paymentsForm\" onsubmit=\"return validate()\">"; echo "<input type=\"checkbox\" name=\"deleted\" id=\"del\"></td>"; echo "<input type = \"submit\">"; echo "</form>"; ?> Many thanks in advance Link to comment https://forums.phpfreaks.com/topic/161097-checkbox-validation/ Share on other sites More sharing options...
Axeia Posted June 5, 2009 Share Posted June 5, 2009 Not quite sure what you're trying to do, but you need to add a return value to the validate function. 'return true' when it does what you want. 'return false' when it doesn't do what you want, so it doesn't get submitted. Link to comment https://forums.phpfreaks.com/topic/161097-checkbox-validation/#findComment-850124 Share on other sites More sharing options...
sseeley Posted June 5, 2009 Author Share Posted June 5, 2009 I just want the validate to alert me and the form to tell me what the status of the checkbox is? Whether it is 'Checked' or 'Not Checked'. It is just a test form Link to comment https://forums.phpfreaks.com/topic/161097-checkbox-validation/#findComment-850147 Share on other sites More sharing options...
Axeia Posted June 5, 2009 Share Posted June 5, 2009 function validate() { var deleted=document.getElementById("del").checked; alert(deleted); return false; } Link to comment https://forums.phpfreaks.com/topic/161097-checkbox-validation/#findComment-850169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.