• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

Textbox or Textarea limiting the number of lines and characters per line

I have a textbox that needs to be parsed into three lines of 60 characters max that will be stored in a database.  The user needs to have the format that they enter the data into the textbox remain consistent with how it will be stored in the database fields.  I can size the textbox so that it will wrap correctly at 60 characters but I don't know how to stop them after they enter the 60th character on the third line.

Thanks for any insight.
0
Tibruk
Asked:
Tibruk
1 Solution
 
contactkarthiCommented:
0
 
BenMorelCommented:
Hi, this wraps the input at 60*3 chars, but is it what you're looking for ?
<textarea cols="60" rows="3" onkeyup="this.value = this.value.slice(0, 60*3);"></textarea>

Ben
0
 
scrathcyboyCommented:
nice Ben -- if you can add some JS to put in <CR>s at the end of each line (not here but generally speaking) you have a great thumbnail script.  However, the asker may want to force a CR at the end of 60 chars, I think that is what he is asking, not sure.
0
 
gatorvipCommented:
>>However, the asker may want to force a CR at the end of 60 chars, I think that is what he is asking, not sure.

If that's the desired result, it can be achieved during the db insert process ( something like textarea.value || char(10). IMO that doesn't really make sense as it would just be a redundant character stored in the db.

0
 
BenMorelCommented:
I think what you need to add to me code above is the css property :
word-wrap: break-word;

But unfortunately it's not implemented yet in all browsers, so you have to use hacks like this one :
http://blog.stchur.com/2007/02/22/emulating-css-word-wrap-for-mozillafirefox/

Ben
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now