CORT0619 Posted December 17, 2012 Share Posted December 17, 2012 I'm creating a form and I don't know much javascript but I have a value that displays in a textbook before the user enters anything and I would like to clear the textbook on click but I was wondering if I could set it to only be cleared on the first click or something like that because if the user enters a value and accidentally clicks again I don't want that value to be cleared. Thanks, -Crystal. Quote Link to comment https://forums.phpfreaks.com/topic/272118-onclick-event/ Share on other sites More sharing options...
Drongo_III Posted December 17, 2012 Share Posted December 17, 2012 (edited) Hi Crystal Something like this should point you in the right direction: <script> function removeText(){ var textArea = document.getElementById("text"); if(textArea.value == 'Please add your comment'){ textArea.value = ''; } } </script> <form> <textarea id="text" onfocus="removeText();">Please add your comment</textarea> </form> The onfocus event is useful for form elements. When the user clicks into the field (making it the focus) then the function will fire. Hope that helps. Drongo I'm creating a form and I don't know much javascript but I have a value that displays in a textbook before the user enters anything and I would like to clear the textbook on click but I was wondering if I could set it to only be cleared on the first click or something like that because if the user enters a value and accidentally clicks again I don't want that value to be cleared. Thanks, -Crystal. Edited December 17, 2012 by Drongo_III Quote Link to comment https://forums.phpfreaks.com/topic/272118-onclick-event/#findComment-1399977 Share on other sites More sharing options...
CORT0619 Posted December 18, 2012 Author Share Posted December 18, 2012 Thanks Drongo this is perfect! Quote Link to comment https://forums.phpfreaks.com/topic/272118-onclick-event/#findComment-1399981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.