I am trying to generate a alert message .When radio button does not select. Here is my code.
<form method=post name="spendform" id="spendform">
<input name="price" type="radio" class="invest-coin-check" id="pricemethod" >
<button type=submit class="btn btn-lg btn-p-h btn-bw" id="mypayment">Make Investmen
t Here is java-script code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#mypayment').click(function () {
if ($('#pricemethod').val() == '') {
alert('Please Select Payment options');
return false;
}
});
});
</script>
Here:
$('#mypayment').click(function(){
if($('#pricemethod').is(':checked')){
alert('Please Select Payment options');
}else{
$('#spendform').submit();
}
});
.is(':checked') by MH2K9
Use .is(':checked')
instead of .val()
. .is(':checked')
returns true
if it is checked, otherwise it returns false
.
$(document).ready(function() { $('#mypayment').click(function(){ if(!$('#pricemethod').is(':checked')){ alert('Please Select Payment options'); return false; } }); });
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <form method=post name="spendform" id="spendform"> <input name="price" type="radio" class="invest-coin-check" id="pricemethod" > <button type=submit class="btn btn-lg btn-ph btn-bw" id="mypayment">Make Investmen</button> </form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.