I have added a jQuery script to check if checkbox is checked or not.
If checked doing something and If not doing something else.
Here is my jQuery code:
jQuery('#mybtn').click(function (e) {
e.preventDefault();
if (jQuery('#mytc').is(':checked')) {
jQuery('#myfrm').attr('action', 'http://test.php');
jQuery('#checkerror').html('');
} else {
jQuery('#checkerror').html('Please agree to the Terms and Conditions.');
}
});
<form id="myfrm">
<p>Lorem ipsum dolor</p>
<input type="checkbox" id="mytc" value=""/>
<label class="yogatctxt">I agree to the <a href="#" target="_blank">Terms and Conditions</a>.</label><br>
<span id="checkerror" style="color: red;font-size: 12px;"></span>
<br>
<br>
<input type="submit" id="mybtn" value="Proceed to Checkout"/>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
So when I submit Process to Checkout button it still shows same page. Where is the problem?