Menu
I need to limit input in a textarea element to 6 rows of no more than 75 characters each. (This is a restriction that will be applied when the information is later printed to close the transaction.)
I’ve searched HTML and JavaScript forums and have found ways to count characters, but it would be much simplier to count ROWS (as well as characters), since each row could hold different numbers of characters <=75, and I am definitely limited to 6 rows. Is there a way to do this?
Thank you,
Moreta
You could use Javascript to check each row individually and see if each of the six rows is greater than 75 characters. [/QUOTE]That's what I'd like to do... as well as making sure they don't enter more than 6 rows worth of text. So far everything I've come up with to try to do it on the fly is really... [i]bad[/i] and I end up confused by my own code. ?
if(document.formname.textareaName.value.split("n").length > [/quote]I recognize the parts, but would never have come up with this! I'm still playing in the shallows... while all of my goals lie in the depths. ?
I didn't test the code, so I don't know if it will work....[/quote]Jona, you are too modest. It's elegant. ?
//function to limit lines/length of input
function limitLL(val)
{ formObj = document.endform;
if(val.split("n").length > 6) {return false;}
for(i=0;i<6;i++){
if(val.split("n")[i].length > 75){return false;} }
return true;
}
// -->
</SCRIPT>
</HEAD>
<BODY>
...
<TEXTAREA style="width=90%" ROWS="6" WRAP="YES"
NAME="EndRequest" onKeypress="return limitLL
(this.value)"></TEXTAREA>
....
if(x.join("").toString().length>75)[/quote]I'm good up to this statement.... I find toUpperCase, but not toString(). Join seems obvious, but I can't find an explanation on it either. (Obviously, I'm looking in the wrong place.) I haven't found a good reference for JavaScript. One that lists all properties as well as objects. If you know of one, it would be of great help. ("Teach a man to fish....")
I'm still trying to understand why we did the join()... [/quote]
//function to limit lines/length of input
function limitLL(val)
{ formObj = document.endform;
valArray=val.split("n");
for(i=0;i<1;i++){
if(valArray[i].length > 10) {
//add 'x' so I can see what's happening
valArray[i]+="n x";
alert(valArray[i]);
val=valArray.join("");
alert(val);
} }
return true;
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<TEXTAREA style="width=90%" ROWS="6" WRAP="YES"
NAME="EndRequest" onKeypress="return limitLL(this.value)">
</TEXTAREA>
[i]Originally posted by moreta [/i]
[B]Do you see what I've done wrong?
[/B][/QUOTE]
[i]Originally posted by moreta [/i]
[B]The code adds the "n x" to the Textarea for you? :eek: [/B][/QUOTE]
document.endform.EndRequest.value=valArray.join(""); [/quote]
0.1.9 — BETA 6.18