javascript - How to change colour of textbox while typing in textbox? -


i'm using validating form input fields while typing using jquery , script looks this:

var firstname = /^[a-za-z]{3,15}$/; var day = $("#day_birthdate"); jquery('input#firstname').bind('input propertychange', function () {     if (firstname.test(jquery(this).val())) {         jquery(this).css({             'background': '#c2d699'         });      } else {         jquery(this).css({             'background': '#ffc2c2'         });      } });   jquery('input#day_birthdate').bind('input propertychange', function () {     if (day > 1) {         jquery(this).css({             'background': 'green'         });      } else {         jquery(this).css({             'background': 'red'         });      } }); 

i have textbox:

 @html.textboxfor(m => m.register.firstname, new { id = "firstname", @class = "form-control", @maxlength = "16" })  @html.textboxfor(m => m.register.day, new { id = "day_birthdate", @class = "form-control", mask = "99", @placeholder = "dd" }) 

main idea check in javascript if day between 1 , 31 green colour of background while im typing it, if not red colour?

you need value of #day_birthdate , parse value of day integer:

var day = parseint($("#day_birthdate").val(), 10); //                                    ^^^^^^ 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -