Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text in HTML Field to disappear when clicked?

I can easily create a html input field that has text already in it. But when the user clicks on the input field the text doesn't disappears but stays there. The user then has to manually remove the text to type. How can I create an input field where when the user clicks on the input field box the text then disappear?

like image 345
Zach Smith Avatar asked Oct 26 '09 17:10

Zach Smith


People also ask

How do I make text disappear in HTML?

See-through souls. Going, going, gone. You can also make an element so transparent that it's invisible using the opacity CSS property. Like visibility: hidden, opacity: 0.0 will leave an empty space where the HTML element is.

How do you make an input text invisible?

The <input type="hidden"> defines a hidden input field. A hidden field let web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

How to make input value disappear when clicked in javascript?

blur(function () { if(this. value == ''){ this. value = 'ENTER VALUE'; } }); //this will empty the field is the value is the default one $("#valueText").


1 Answers

What you want to do is use the HTML5 attribute placeholder which lets you set a default value for your input box:

<input type="text" name="inputBox" placeholder="enter your text here">

This should achieve what you're looking for. However, be careful because the placeholder attribute is not supported in Internet Explorer 9 and earlier versions.

like image 133
Nachshon Schwartz Avatar answered Oct 04 '22 23:10

Nachshon Schwartz