How to clear html text box values

Posted in HTML, Web Design on April 21, 2017

Here's what's happened to me recently. I have a form on a website with a textbox. I wanted to have predefined default text in the box (like 'Enter Your ID Number') but have it disappear when the cursor clicks the box. I originally used onFocus="clear_textbox()" but that stopped working. So I then changed it to onclick="this.value=''; and it works like a charm! Here's working example (minus the submit button):

And here's a code example:

<form name="text_form" id="text_form">
<input name="userid" type="text" onclick="this.value='';" value="Enter Your ID Number" size="25"/>
<input type="submit" value="Set ID" />

Leave a Reply

Your email address will not be published. Required fields are marked *