javascript - How do I reset a checkbox thats checked value is set by php? -
javascript - How do I reset a checkbox thats checked value is set by php? -
i have web form bazillion check boxes. if form filled out incorrectly, none of check boxes reset (as anti-frustration feature).
problem is, reset button doesn't work uncheck boxes if form has been submitted before. how prepare this?
document.getelementbyid("form").reset()
doesn't work if form has been submitted beforehand either.
sample code below:
<body> <script> function resetdata() { document.getelementbyid("deletecontactflag").checked=false; document.getelementbyid("useradministrationflag").checked=false; } </script> <form action="<?php echo htmlspecialchars($_server["php_self"]); ?>" method="post" id="form"> <input type="checkbox" name="deletecontactflag" id="deletecontactflag" <?php if (isset($_post["deletecontactflag"])) echo 'checked="checked"'; ?>/> delete contacts<br> <input name="useradministrationflag" type="checkbox" id="useradministrationflag" <?php if (isset($_post["useradministrationflag"])) echo 'checked="checked"'; ?>/> user administration<br><br> <input type="submit" name="submit" id="submit" value="submit"> <button type="button" onclick="resetdata()">reset</button> </form> </body>
the form reset not clear values in form, sets form it's initial state, had when page first loaded. (in initial state checkboxes checked.)
try resetting checkboxes manually:
var inputs=document.getelementsbytagname("input"); (var in inputs) if (inputs[i].type=="checkbox") inputs[i].checked=false;
or if utilize jquery:
$("input[type=checkbox]").each(function() { this.checked=false; });
javascript php checkbox
Comments
Post a Comment