Click to See Complete Forum and Search --> : Adding a limiter in the TextArea box
Vagabond
07-01-2004, 11:03 AM
Hi All,
I want to add a limiter tag (either an image or some character like <<$$@@>>in the TextArea Box say after 255 characters which is visible before you edit anything in the TextArea box so that the user know where exactly 255 characters end? Could anyone mail me the source code or post it in this forum itself. I would appreciate that.
Thanks
David Harrison
07-01-2004, 11:15 AM
Here is some code that just won't let them type in more than 255 characters.<textarea onkeyup="if(this.value.length>255){this.value=this.value.substring(0,255);}"></textarea>If your users are savvy enough though they could just make their own form that submits to your site, then you'll need some server-side restrictions in place.
Vagabond
07-02-2004, 04:06 AM
Hi Lavalamp,
Thanks for the code. Is there anyway where in I can give the permissions only for the admin to enter more than 255 characters for web description. I also want the limiter tag to be visible in the TextArea box so that other users who want to edit in the teaxbox know exactly where the 255 characters end. I have written the code but when I edit the texbox area the limiter tag appears only if you have reached 255th character. Please Help!
Thanks
Pittimann
07-02-2004, 04:22 AM
Hi!
Why not simply use a counter instead of the limiter tag??
Cheers - Pit
Vagabond
07-02-2004, 07:14 AM
Hi Pittiman,
I have used counter also. But the client is very particular. He says he wants to see a limiter tag in the TextArea box.
Pittimann
07-02-2004, 07:24 AM
Hi!
How does your client know, how many line breaks the user will enter?
Cheers - Pit
russell
07-02-2004, 12:56 PM
Here is some IE code. You'll need to add logic for NS, and code to determine which browser. Also, I leave to you to capture Carriage Returns, backspaces and form resets (reseed the variable tIdx).
I've created a limit of 25 characters and used "*" as my delimiter.
<script><!--
tIdx = 0;
function replChar() {
if(tIdx > 24) return false;
key = event.keyCode;
alert(key);
str = document.f.t.value.substr(0, tIdx);
str += String.fromCharCode(key);
spacer = ""
for(i=24; i > tIdx; i--) {
spacer += " ";
}
spacer += "*";
document.f.t.value = str + spacer;
tIdx += 1;
return false;
}
// -->
</script>
</HEAD>
<BODY>
<form name=f>
<textarea rows=2 cols=25 name=t onkeypress="return false" onfocus="document.f.u.focus()"> *</textarea>
<br>
<textarea rows=2 cols=25 name=u onkeypress="return replChar()"></textarea>
</form>
will work in IE only (event.keyCode)
Vagabond
07-07-2004, 01:57 AM
Hi,
Could you post me the code to find out the cursor positions in the TextArea box?
Thanks...I aprreciate your help in this regard..
Cheers!