开发者

jQuery custom validate option

开发者 https://www.devze.com 2023-03-26 09:12 出处:网络
Is there a way to validate a form instead of rules? For example: 开发者_高级运维In the form there are 3 check boxes;

Is there a way to validate a form instead of rules?

For example:

开发者_高级运维

In the form there are 3 check boxes; i want to test if none of them is selected - in which case, return false and prevent the form from submitting


HTML :

<input type="checkbox" name="event[]" id="event" value="click">click<br> 
<input type="checkbox" name="event[]" id="event" value="focus">focus<br> 
<input type="checkbox" name="event[]" id="event" value="change">change<br>

jQuery :

$(document).ready(function() 
{ 
    $("form").submit(function() 
    { 
       var checked = $("input[@id=event]:checked").length; 
        if (checked == 0) 
        { 
            alert ("Please select at least one event"); 
            return false; 
        } 
        else 
        { 
            return true;
        }
    });
});

Please do above steps and let me know if any.


         submitHandler: function(form) {

        if ( $('input[type="radio"]').is(':checked')==true){
            form.submit() ;  
        }else{
            alert("Please choose option");
        }
     }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号