Detecting carriage returns within a string - using charAt() or indexOf() ???

They have: 5,633 posts

Joined: Jan 1970

I have a form with a TEXTAREA where you type in a message. Once the form has ben submitted, the value within the TEXTAREA as saved as a variable.

How can I detect if a carriage return (eg. ENTER has been pressed within the TEXTAREA) has been used?

I can detect numbers and letters fine but cannot detect carriage returns. To help you out, I use the charAt() and indexOf() methods to manipulate variables.

----------
[email protected]
vegas.com.au/~jasper

They have: 112 posts

Joined: Apr 1999

You should use the indexOf() function to detect the carriage returns. To detect newlines or carriage returns in the textarea ,use the escape sequences, "\n" and "\r" respectively.
Below is an example to detect newlines in a textarea:

var pos = document.myForm.textArea.indexOf("\n");

Have a try.
Later.

----------
Elara - Webmasters' Guide
http://elara.hypermart.net/

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.