2

i dont know even how this is name. If i add here new question then i title is disappearing hits. I can add default value in input, but this isnt this. Here is another. How can i make this? And how can i make this in input password? There is *, so how can i write in clean text? Generally what this is name?

Thanks for help!

<form>
First name: <input type="text" name="firstname" value="First Name" /><br />
Last name: <input type="text" name="lastname" value="Last Name" /> <br />
Password: <input type="password" name="pwd" value="password" />
</form> 

3 Answers3

0

Use placeholder attribue ;)

<input type="text" placeholder="default text" />
<input type="password" placeholder="default text" />
ChristopheCVB
  • 7,269
  • 1
  • 29
  • 54
0

I think this is what you're looking for:

<input type="password" name="pwd" value="password" placeholder="Enter password" />

However it will only work in some browsers. So if you want to support the majority, you'll need some js to pre-fill it. Google 'html input hint' or 'placeholder'. There are js plugins for this out there.

Here's a related stackoverflow thread: How do I make an HTML text box show a hint when empty?

Community
  • 1
  • 1
Zhenya
  • 220
  • 1
  • 8
0

I recommend a combination of the placeholder attribute and feature detection so you know whether the browser supports it, and falling back on JavaScript code if it doesn't.

So your markup would be:

First name: <input type="text" name="firstname" placeholder="First Name" />

...and it'll get handled by browsers that support it, ignored by ones that don't.

The feature detection is easy:

var text = document.getElementById("yourfieldid");
if ("placeholder" in text) {
    // The browser supports placeholders, your markup should be sufficient
}
else {
    // Browser doesn't, need to do something with JavaScript
}

I've written a jQuery plug-in that does this.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875