Limit input Textarea 
Author Message
 Limit input Textarea

Hai,

I hava a textarea of 4 rows and 79 coloms.
Now what I want to do is add a limit to the number of rows a user may use.
The rows don't need to be full. Is there anyone who can help me?

The Sorcerer



Sun, 27 Jun 2004 19:11:15 GMT  
 Limit input Textarea
The best you can
Use the "onChange" event, for example:

<FORM NAME="form_one">
<TEXTAREA NOWRAP onChange="checkThis();" NAME="toCheck">Text</TEXTAREA>
</FORM>

<SCRIPT LANGUAGE="JavaScript">
<!--
function checkThis() {
 var theTextAreaBreaks = document.form_one.toCheck.value.split("\n");
 if (theTextAreaBreaks.length > 4 {
  alert("You cannot use more than four rows!");
  document.form_one.toCheck.value = theTextAreaBreaks[0] + "\n";
  document.form_one.toCheck.value += theTextAreaBreaks[1] + "\n";
  document.form_one.toCheck.value += theTextAreaBreaks[2] + "\n";
  document.form_one.toCheck.value += theTextAreaBreaks[3];
 }

Quote:
}

// -->
</SCRIPT>

This function checks to see how many line breaks are in the form.
Unfortunately, you have to turn of wrapping in the text box for this to
work.  Otherwise, you would just have to say:
 if (document.form_one.toCheck.value.length > (79*4)) {
  alert("You cannot use more than four full rows!");
 }

JavaScript doesn't see rows of text; it just sees one big string.

Good luck!

--Robert Paveza


Quote:
> Hai,

> I hava a textarea of 4 rows and 79 coloms.
> Now what I want to do is add a limit to the number of rows a user may use.
> The rows don't need to be full. Is there anyone who can help me?

> The Sorcerer



Mon, 28 Jun 2004 11:31:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Limit Textarea to 72 characters per line

2. Text area input width limit

3. how to make HTML paragraphs from textarea input

4. Select highlighted text from TEXTAREA or TEXT input

5. How to use javascript to limit input text in a TEXTAREA?

6. <TEXTAREA> Can I limit character input?

7. Validating input from input box against an array of suitable inputs

8. Textarea.value -- textarea has no parameters

9. How do I limit length of text in textarea?

10. Is it possible to limit a textarea so it works both in NS and IE?

11. Finding caret position for textarea and input elements - HELP!

12. POST data too long for URL limit

 

 
Powered by phpBB® Forum Software