Possible Duplicate:
How to limit number of characters per line in text area to a fixed value.
hello Friends,
I have a textarea field in my view.
I need to set per line 72 characters length.
that is user is entering more than 72 chracter per line I need go to next line.
How to set these limits using jquery or javascript?
Thanks
This is not standard, but it works in many browsers, test it.
http://www.htmlcodetutorial.com/forms/_TEXTAREA_WRAP.html
<TEXTAREA NAME="HARD" COLS="72" ROWS="5" WRAP="HARD">
Setting wrap to hard makes it send new lines to the server. Setting it to soft only breaks it visually.
No need to use javascript for this. There is a HTML attribute built into the <textarea>
tag.
See some documentation here.
example for your use
<TEXTAREA NAME="HARD" COLS=72 ROWS=5 WRAP=HARD></TEXTAREA>
Using a HARD
Wrap actually sets carriage returns when the line is wrapped.
I may be a bit late posting this answer, but this is best done with javaScript to ensure browser compatibility. With jQuery we can do
var count= 1;
var chars= 3;
$('#mytext').keydown(function() {
var v = $(this).val();
var vl = v.replace(/(\r\n|\n|\r)/gm,"").length;
if (parseInt(vl/count) == chars)
{
$(this).val(v + '\n');
count++;
}
});
Check working example at http://jsfiddle.net/ZWVad/2/
精彩评论