3
I would like to do a validation via jQuery, to know if the client has selected some RadioButton
It displays an Alert if it has not selected, but it still sends (submited), it should not.
HTML
<table id="RadioButtonList1" cellspacing="15" cellpadding="15">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">opc 01</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_1">opc 02</label></td>
</tr><tr>
<td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="3" /><label for="RadioButtonList1_2">opc 03</label></td>
</tr><tr>
<td><input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="4" /><label for="RadioButtonList1_3">opc 04</label></td>
</tr><tr>
<td><input id="RadioButtonList1_4" type="radio" name="RadioButtonList1" value="5" /><label for="RadioButtonList1_4">opc 5</label></td>
</tr>
</table>
<input type="submit" name="Button1" value="Votar" id="Button1" class="btn btn-primary" />
JS
jQuery(function(){
jQuery('#Button1').bind('click',checkRadio);
})
function checkRadio() {
var isChecked = jQuery("input[name=fileType]:checked").val();
var booleanVlaueIsChecked = false;
if (!isChecked) {
booleanVlaueIsChecked = true;
alert('Selecione algum logotipo');
}
}
Missed giving
preventDefault
click generated event when you do not want to submit the form. Additionally you need to declare the event as a function parameter.– Wakim
I added relevant parts of the code to the question to facilitate understanding.
– abfurlan