Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 190438  / 14 Years ago, thu, may 6, 2010, 12:00:00

Given a <textarea> with a default value as follows:



<textarea>Please describe why</textarea>


How do you clear the default value when the user clicks to edit the field?


More From » html

 Answers
37

Your JavaScript:



function clearContents(element) {
element.value = '';
}


And your HTML:



<textarea onfocus=clearContents(this);>Please describe why</textarea>


I assume you'll want to make this a little more robust, so as to not wipe user input when focusing a second time. Here are five related discussions & articles.



And here's the (much better) idea that David Dorward refers to in comments above:



<label for=explanation>Please describe why</label>
<textarea name=explanation id=explanation></textarea>

[#96859] Tuesday, May 4, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zackeryzainv

Total Points: 61
Total Questions: 102
Total Answers: 99

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;