someoneb100 someoneb100 - 1 year ago 47
jQuery Question

JQuery form of radio input

I am trying to make a simple form of radio inputs where at most 1 can be selected:

<form id='forma' action='predmeti.php' method='GET'>
1:<input type='radio' name='godina' value='1'/>
2:<input type='radio' name='godina' value='2'/>
3:<input type='radio' name='godina' value='3'/>
<input type='button' id='ok' value='Izaberi godinu!'>

How do i allow form submit only if one is selected and prevent submit if nothing selected? The form is submited by clicking on the id='ok' button.


Updated based on comment. Please try this.

$(document).ready(function() {
       $('#ok').on('click', function(){
        if($("#forma input[type='radio']:checked").length == 1){