Setting an attribute in Jquery not working -


i have following function limits amount of characters can enter text area.

what's meant happen is, if text length higher text limit, set attribute of disabled="disabled" on submit button, isn't getting set, function code follows:

function limitchars(textid, limit, infodiv) {         var text = $('#'+textid).val();          var textlength = text.length;         if(textlength > limit) {             $('#' + infodiv).html('you cannot write more '+limit+' characters!');             $('input#submit').attr('disabled', 'disabled');          } else {             $('#' + infodiv).html('you have '+ (limit - textlength) +' characters left.');          }     } 

it's $('input#submit').attr('disabled', 'disabled'); bit isn't working.

any ideas?

i posted a demo , appears work code:

$(document).ready(function(){  $('#test').keyup(function(){   limitchars( this.id, 20, 'info')  }) })  function limitchars(textid, limit, infodiv) {  var text = $('#'+textid).val();   var textlength = text.length;  if(textlength > limit) {   $('#' + infodiv).html('you cannot write more '+limit+' characters!');   $('input#submit').attr('disabled', 'disabled');  } else {   $('#' + infodiv).html('you have '+ (limit - textlength) +' characters left.');   $('input#submit').removeattr('disabled');  } } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -