Hi
I am trying to make a bit of javascript to limit the number of lines of text that can be put in a text area. At the moment it does limit the number of lines, but it needs to take wrapping into account. (i.e. if 3 lines are permitted, and there are already 2 lines because one has wrapped, it needs to consider this).
I am basing it on a script I found on the 'net.
To account for the wrapping, I propose having the JS insert a linebreak after a certain number of characters (I can write a regex to do this possibly), but the problem is that I don't know how to reference the following lines object(?)
The code is something like this:
Lines can be accessed as an associative array (e.g. if I print lines[0], I get everything up to the first carriage return entered by the user). If I just print lines, I get the entire contents of the object.
What I need to do is have a way to reference the current 'line' and insert a linebreak after n characters. I think this would then *almost* do what I want?
Any ideas much appreciated.
Thanks
I am trying to make a bit of javascript to limit the number of lines of text that can be put in a text area. At the moment it does limit the number of lines, but it needs to take wrapping into account. (i.e. if 3 lines are permitted, and there are already 2 lines because one has wrapped, it needs to consider this).
I am basing it on a script I found on the 'net.
To account for the wrapping, I propose having the JS insert a linebreak after a certain number of characters (I can write a regex to do this possibly), but the problem is that I don't know how to reference the following lines object(?)
The code is something like this:
PHP:
var lines=el.value.replace(/\r/g,'').split('\n'),
i=lines.length,^M
lines_removed,^M
char_removed;
Lines can be accessed as an associative array (e.g. if I print lines[0], I get everything up to the first carriage return entered by the user). If I just print lines, I get the entire contents of the object.
What I need to do is have a way to reference the current 'line' and insert a linebreak after n characters. I think this would then *almost* do what I want?
Any ideas much appreciated.
Thanks