Created
April 13, 2018 01:49
-
-
Save mazfreelance/73291a614f6af4778d8e9802b8a9b6ff to your computer and use it in GitHub Desktop.
validation checkbox select atleast one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//html | |
<input type="checkbox" class="checkbox" name="checkbox[]" value="checkbox 1"/> | |
<input type="checkbox" class="checkbox" name="checkbox[]" value="checkbox 2"/> | |
<p id="validation"></p> | |
//form submit | |
$('#form-id').submit(function(evt){ | |
evt.preventDefault(); | |
... | |
if(!$('.checkbox').is(":checked")) { | |
document.getElementById("validation").innerHTML="Please select atleast one checkbox"; | |
return false; | |
} | |
... | |
}); | |
//hide error validation if user click atleast one checkbox. | |
$(".checkbox").click(function(){ | |
$(this).is(':checked') ? $('#benefit_valid').hide() : $('#benefit_valid').show(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment