Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea problem

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi all

I am using the following code for an textarea box that I have.
I want this box to allow the user input a max of 200 character which is
working but a funny thing happens when you want to go back using the
back arrow, it automatically goes to the end of the sentence ie it doesn't stay where you want it to. I assume the keyup value has something to do with this. I don't fully understand the code below so If someone could help me fix this problem, would be most grateful.

<textarea name="feedback" onkeyup="this.value = this.value.slice(0, 200)"rows="5" cols="40">
<?php if(isset($_SESSION['feedback'])) echo stripslashes($_SESSION['feedback']);?>
</textarea>


Tks

Graham
 
You are completely replacing the contents of the textarea after every keystroke, so the browser loses its place and has no idea where to put the cursor.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I don't believe you can fix it without entirely changing the way you're handling the textarea overflow.

Instead of just lopping off any extra, you could just COUNT the number of characters, and warn the user when they area getting close to the limit. You can put the number of characters entered so far into a text field or even insert them into a span.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Code:
<textarea name="feedback" onkeyup="if(this.value.length > 200) this.value = this.value.substr(0, 200);" rows="5" cols="40">
<?php if(isset($_SESSION['feedback'])) echo stripslashes($_SESSION['feedback']);?>
</textarea>

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top