jquery - when <textarea> character count reaches 30 enable <button> -
i want display number (30) below <textarea>
count characters inside it.
it decreases characters being typed/pressed.
im using $j
required wordpress avoid conflict.
this fiddle http://jsfiddle.net/jgmcn/1/
var $j = jquery.noconflict(); $j(function(){ $j("#textarea").keyup(function(){ count = $(this); // insert values here $j("#charnum").text(30); // display 30 if ($j(this).val().length >= 30 ) // if value length >= 30 then... { $j("#charnum").text(30 - count.val().length)); //display while subtracting 'count' 30 } else (30-count.val().length == 0) //if value == 0 { $j("#charnum").text("submit enabled"); //print $j("#submit").removeattr('disabled'); // allow submit button { }); });
you have large number of errors in code. since you're using jsfiddle, i'd suggest using jshint function , working through them next time.
to function suggested, final jquery was:
var $j = jquery.noconflict(); $j("#textarea").on("keyup keydown keypress", function(){ //captures key input, not necessary var count = $j(this); //you missing 'var' , using $ instead of $j if ($j(this).val().length <= 30 ) { $j("#charnum").text(30 - count.val().length); //you had unmatched bracket here } else { //could not compare bracketed values else, use else if, or no if @ $j("#charnum").text("submit enabled"); $j("#submit").removeattr('disabled'); } //your closing bracket front });
edit: don't forget, if want limit text input, can use maxlength
attribute textarea, set number of characters want limit to. works in modern browsers and, far recall, ie 7 or 8, forget which.
Comments
Post a Comment