I'm looking for a good way to add input prompts to my HTML form fields- The same way StackOverflow uses light gray text as prompts within all of its text fields.
Figured there would be a jQuery plugin out there, but so far haven't found anything good. Anybody?
The prompt() method displays a dialog box that prompts the user for input. The prompt() method returns the input value if the user clicks "OK", otherwise it returns null .
This is not possible with an OS or native browser window popping up. You will have to create a custom overlay dialog. I would advise using a library like jQuery UI to do this. You can then customize whatever is in the popup.
The required attribute is a boolean attribute. When present, it specifies that an input field must be filled out before submitting the form.
See the answers to this question: Jquery default value in password field
In html5 you can do this:
<input type="text" placeholder="Default Value"/>
This is what SO does if you view the search bar on top:
<input name="q" class="textbox" tabindex="1" onfocus="if (this.value=='search') this.value = ''" type="text" maxlength="140" size="28" value="search">
If you mean having light grey text inside the form field, you can use the placeholder
attribute in recent browsers:
<input type="text" placeholder="This text will appear inside the form field until the user focuses it">
I don’t know of any packaged jQuery plug-ins that mimic this functionality in browsers that don’t support placeholder
, but here’s an example of how to do it yourself in jQuery:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With