Jump to content

Onclick Event


CORT0619

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/272118-onclick-event/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/272118-onclick-event/#findComment-1399977
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.