I am using the following Javascript code to validate that at least one of the radio inputs are checked before submitting the form, but I am facing a problem as the form always submit even if there are no radio inputs checked...can someone please help by telling me what I am missing here and how to fix it? Thanks
<script type="text/javascript">
function processPayment() {
if ($("input[name='orderAmount']:checked").length > 0){
alert('OK');
document.getElementById('orderFrm').submit();
return false;
}
else{
alert('Please select order amount');
}
}
</script>
<div id="content">
<form id="orderFrm" name="orderFrm" action="https://...." method="post" target="_top">
....
<div class="orderamnt">
<label for="orderAmount50">
<span class="labelText">50</span>
<input type="radio" id="orderAmount50" name="orderAmount" value="50"/>
</label>
</div>
<div class="orderamnt">
<label for="orderAmount100">
<span class="labelText">100</span>
<input type="radio" id="orderAmount100" name="orderAmount" value="100"/>
</label>
</div>
<div class="orderamnt">
<label for="orderAmount200">
<span class="labelText">200</span>
<input type="radio" id="orderAmount200" name="orderAmount" value="200"/>
</label>
</div>
<a class="buyNowButton" href="javascript:{}" onclick="processPayment()">Order</a>
....
</form>
</div>
Note:
I noted when checking any of the radio buttons that it changes from:
<div id="orderamnt">
<span class="">
<input type="radio" id="orderAmount200" name="orderAmount" value="200"/>
to...
<div id="orderamnt">
<span class="checked">
<input type="radio" id="orderAmount200" name="orderAmount" value="200"/>
obviously the radio input don't have checked and that's why obviously it is not working on my side, so wondering is there a way I can validate the first parent span from the radio button?