drupal - Limiting lines and char count per line in a textarea with jQuery -


i have drupal webform textarea limit line , character per line when option selected, related textarea.

example, user picks option a, textarea should limited 2 lines, , 14 characters per line. option b, 3 lines, 18 characters. on , forth.

i cannot seem interact webform through hook_form_alter add attributes textarea javascript callback. assume first issue. able jquery however.

$(document).ready(function() {  $('#mytext').keyup(function() {     var v = $(this).val();     var vl = v.replace(/(\r\n|\n|\r)/gm, "").length;     if (vl == 0) {         count = 1;     }     if (parseint(vl / count) == chars) {         $(this).val(v + '\n');         count++;     }      if (count > 3) {        var text = $('#mytext').val();        var lines = text.split('\n');         var test = implode('\n', lines);         alert(test);     }  }); }); 

also, how can count lines , characters per line, , prevent typing if limits met?

i borrowed part of above here:

characters per line , lines per textarea limit

this limit textarea 3 characters per line. change chars increase number of characters per line.

var count = 1; var chars = 3; $('#mytext').keyup(function() {     var v = $(this).val();     var vl = v.replace(/(\r\n|\n|\r)/gm, "").length;     if (vl == 0) {         count = 1     }     if (parseint(vl / count) == chars) {         $(this).val(v + '\n');         count++;     }  }); 

check working example @ http://jsfiddle.net/7jvrt/


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -