javascript - submit form check if checkbox is checked -
i use form signup checkbox 'terms of use'
<form action="/signup/signup_success.html" id="regform" class="form-horizontal" novalidate="novalidate" autocomplete="off"> <fieldset> <div class="checkbox"> <label for="agb" id="checkbox_validate" class="hide success">please accept terms of use</label> <label> <input type="checkbox" name="agbcheckbox" id="agbcheckbox"> yes <a target="_blank" href="http://example.de">datenschutzbestimmungen</a>. </label> </div> <div class="buttonwrapper"> <button type="submit" class="try-button" > register </button> </div> </fieldset> </form> <script> //check if checkbox terms of use checked or not $("#regform").submit(function(event) { if ($('#agbcheckbox').prop('checked')) { $('#checkbox_validate').removeclass('show').addclass('hide'); //checkbox terms of use checked } else { //checkbox terms of use not checked $('#checkbox_validate').removeclass('hide').addclass('show'); } }); </script>
if add "action="/signup/signup_success.html" form, checkbox validation not work anymore. if set action action="" validation works correctly. don´t find problem. thank help!
this need
event.preventdefault();
http://jsfiddle.net/ergec/l8y8s/
also suggest read better understand difference between event.preventdefault
, return false
Comments
Post a Comment