Welcome to WebmasterWorld Guest from 220.127.116.11
Forum Moderators: open
etc.. sorry i could not post it here, it cut cutting it off half way!
that works fine so far, it limits the number of characters no problem, but the problem is it does not take into account line returns,
i.e. the textarea i am using is roughly 30 characters wide, and i need the script to take this into account. i am building a ecard system and there is limited space on the card for the message text, it all works fine until the user uses line returns. these need to be counted as if the user had typed in '30' characters. does that make any sense?
these need to be counted as if the user had typed in '30' characters.
What you're after can be done:
You want to find the position of the first newline char in the string like this:
var myPosition = myString.indexOf("\n")
You have to do some maths to work out how many to add to the char count (e.g. if it's in position 42 you add 18).
You then have to chop of the first part of the string (including the newline char) and search for a newline again in case there's more than one (and do the maths again). Repeat until there are no more newlines.