-2
I wrote this function to validate some form specific radio Buttons. As my page is in PHP and I do include from the top and footer, the function works when it is in footer.php, but since the function does not apply to all pages, I have to put individually on the body of the specific pages. When I do this mysteriously it doesn’t work and reports errors on the console.
$(function(){
$('body').on( 'change', ':radio', function(){
if( $('input[value="3"]:checked').length > 5 ){
alert('Somente 5 opções críticas podem ser marcadas');
$(this).prop({ checked : false });
}
});
});
Works for me. You can post your HTML? http://jsfiddle.net/WSbE5/ Note that this selector only looks for inputs with
value="3"
– Sergio
When you put in the
BODY
Are you loading jQuery before that code is read? Or only load jQuery at the bottom of the page? You get an error in the browser console?– Zuul
Boy, my HTML has 2000+ lines. = p
– Leandro RR
@Zuul Yes, jQuery is in header.php, that is, at the top between the
<head></head>
– Leandro RR
@Leandroruel, your checkboxes are in HTML
value="3"
? You have a link?– Sergio
And regarding what Sergio asked about the limitation that your code has to only work with
input
whose value is 3? Did you notice that particularity? Ps: You can make a test of this kind to know if the code works but does not match with your elements.– Zuul
@Zuul found that it was this same, the value of the form was different, as the form is super large, it was being difficult to search all inputs, it was with value "a|3", now I have arranged here.
– Leandro RR
@Sergio Responde tackling the problem so Leandro Ruel can close this issue. And Leandro nothing like a good test ;)
– Zuul
This question seems to be discounted because it is too localized
– Sergio
@Zuul was a mistake.
– Leandro RR
@Leandroruel Is a common problem to all programmers and happens to all :)
– Zuul