Textarea Shows Message Appear And Disappear Onclick
- Forums
- Javascipt
- Textarea Shows Message Appear And Disappear Onclick
textarea shows message appear/disappear onclick - today i was looking at youtube, they have a textarea for putting comments and there is a message that says: respond to this video... [2237], Last Updated: Mon Jun 24, 2024
Notredemis
Mon Oct 25, 2010
8 Comments
2987 Visits
today i was looking at youtube, they have a textarea for putting comments and there is a message that says: Respond to this video...
as soon as the user clicks inside the textarea field, the message disappears. i like to know how they did that. i have tried but my javascript skills are limited. so i was wondering if you know of a function i can use to make it apear and disapear text when someone click inside the text area?
also, if its possible, i like to by dynamic with using ajax, if not, i guess ill settle for something static.
<script type="text/javascript"> var TextMessage = 'Respond to this video...'; function SetMsg (txt, active) { if (txt == null) return; if (active) { if (txt.value == TextMessage) txt.value = ''; } else { if (txt.value == '') txt.value = TextMessage; } } window.onload=function() { SetMsg(document.getElementById('TxtareaInput', false)); } </script> <style type="text/css"> .txtBox { border: 1px solid #CCC; color: #999; height: 50px; width: 350px; } </style> <form name="frm" action="" method="post"> <textarea cols="1" rows="1" name="TxtareaInput" id="TxtareaInput" class="txtBox" onfocus="SetMsg(this, true);" onblur="SetMsg(this, false);" ></textarea> </form>DEMO: