We help IT Professionals succeed at work.

How do i add a carriage return to an onclick of a textarea?

bemara57
bemara57 asked
on
357 Views
Last Modified: 2012-06-21
I have a textarea that acts like a comments field that users can add notes to. I want to add an onclick event to the textarea so that it adds two carriage returns, the date and a dash, so the user doesn't have to enter this. For example, if the textarea has this:

------------------------------------
07/08/08 - This is a note.
------------------------------------

When the user clicks into the text area, I want the textarea to become this:

------------------------------------
07/08/08 - This is a note.

07/22/08 -
------------------------------------

With the cursor at the end of the last dash. How can I do this?
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
oops, forgot the carriage return

element.value += "\r\r" + month + "/" + day + "/" + year.substring(2) + " - ";
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.