Jump to content

clear form value when clicked


Woodburn2006

Recommended Posts

this seems really simple but i cannot seem to find this anywhere on the net but when i have a value in a form field i want it to disappear when a user clicks in the field to add their own value, i see it everywhere but cannot find the method of doint it myself

 

thanks alot

Link to comment
https://forums.phpfreaks.com/topic/123836-clear-form-value-when-clicked/
Share on other sites

tmbrown, that'll clear it out even if the user has the content that they want in the box.  You need to make sure that there isn't the default value in there:

 

<script type="text/javascript">
function clearThis(element) {
   if (element.defaultValue == element.value) {
      element.value = '';
   }
}
</script>

<input type="text" name="someinput" value="Enter something here!" onclick="clearThis(this)" />

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.