Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
0 down vote favorite


I have a web form with a bazillion check boxes. If the form is filled out incorrectly, none of the check boxes are reset (as an anti-frustration feature).

Problem is, the reset button doesn't work to uncheck all the boxes. How do I fix this?

document.getElementById("form").reset() doesn't work if the form has been submitted beforehand.

Sample code below:


XML
<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
    <input name="userAdministrationFlag" type="checkbox" id="userAdministrationFlag" <?php if (isset($_POST["userAdministrationFlag"])) echo 'checked="checked"'; ?>/> User Administration

    <input type="submit" name="submit" id="submit" value="Submit">
    <button type="button" onClick="resetData()">Reset</button>
</form>


</body>
[link removed]
Posted
Updated 26-Jun-14 2:38am
v2
Comments
CHill60 26-Jun-14 8:29am    
As an aside I would get rid of the link to your website in the question - firstly it will probably be regarded as spam and secondly it's not a particularly good advert for your services if you have to post questions here.
Might also be an idea to include the code behind the reset button
m2soft solutions 26-Jun-14 8:50am    
i am working for a web designing and development company.... so i upload the questions of developers here.... for solutions...
Wombaticus 26-Jun-14 8:33am    
Have you tried a simple Reset button?
<button type="reset" value="Reset">Reset</button>
m2soft solutions 26-Jun-14 8:47am    
not yet....
but i will do this now....

thanks for quick reply,,...

1 solution

Question has been fully answered on that other site[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900