Sometimes we need to check whether a checkbox is checked or not. We can do this easily by using "checked" attribute of a checkbox.
Example: In the below I have created a function validateCheckBox() that checks whether a checkbox is checked or not.
<html>
<head>
<title>Demo to show div</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function validateCheckBox()
{
if($('#addressCheckBox').is(':checked'))
{
$('#validaddressCheckBox_error').text("");
}
else
{
$('#validaddressCheckBox_error').text("You must check the check box in order to proceed.");
}
}
</script>
<style>
.error{color: #db4437;font-size:14px;}
</style>
</head>
<body>
<div class="col-xs-8">
<input type="checkbox" id="addressCheckBox" class="form-control" onClick="validateCheckBox();">
<label>I confirm this is my address</label>
<span id="validaddressCheckBox_error" class="error emailedCodeError"></span>
</div>
</body>
</html>
Hope this will help you :)
0 Comment(s)