Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea Limit characters per line Jquery or Javascript [duplicate]

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

like image 589
kumar Avatar asked Mar 08 '11 17:03

kumar


People also ask

How do I limit the number of lines and characters in a textarea?

In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.

How do you set a textarea limit?

The HTML <Textarea>maxlength attribute is used to specify the maximum number of characters enters into the Textarea element. Attribute Value: number: It contains single value number which allows the maximum number of character in Textarea element. Its default value is 524288.

How do I limit characters in a line in CSS?

To ensure line lengths don't exceed 80 characters, the CSS max-width property can be set using font-relative lengths of around 70ch or 34em (note that this value will need to be adjusted slightly up or down depending on the font used).


2 Answers

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.

like image 168
Juan Mendes Avatar answered Oct 07 '22 20:10

Juan Mendes


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.

like image 35
jondavidjohn Avatar answered Oct 07 '22 20:10

jondavidjohn