Manual form validation jQuery -
i'm trying manual form validation in jquery hang of it. know there plugins not point.
this code:
$( document ).ready(function() { //amount of input fields need activation of button var amount = $('.form-group').length; //blur checks when leave input field $('.form-group input').blur( function() { //if input empty put red bg color if( !$(this).val() ) { $(this).css("background-color", "red"); } //if field filled in bg white , amount -1. //once amount 1 know fields filled in if( $(this).val() ) { $(this).css("background-color", "white"); amount = amount - 1; if(amount === 1 && $('#tos').prop('checked') ) { //code remove attribute disabled $('button').removeattr("disabled") $('button').html("send") } } }); });
it breaks on following line:
if(amount === 1 && $('#tos').prop('checked') )
both work fine if write them seperate when try use && operator doesn't seem work.
try using additional grouping
if((amount === 1) && $('#tos').prop('checked') )
according operator precedence table ===
has higher precedence &&
code should not need additional grouping though.. hmz.
Comments
Post a Comment