HTML Text Box

Before, I’ve seen text boxes with text already in them. The user could then delete that text and type whatever they wanted. How do I put text in there before the user even touches the form? Thanks!

http://wss.hypermart.net/html/html5.html


<input type=text value="Whiz Kid" name="t1" size=30 maxlength=15>

`value’ holds the default text.

Just for completeness, the text area:


<form>
<textarea rows=6 cols=60 name="ta1">
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This text will appear as default text inside the textbox.
You can't use multiple spaces inside a HTML file,
But in the textbox the text will appear       as the way you type it!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
</textarea>
</form>

All of the text not surrounded by angle brackets is the text field’s default text.

Many Thanks!

Ooh, another question :wink:

I don’t know if this is possible, but can you make it so that when the user clicks in the text box, the text already present disappears automatically, thus saving the user from manually deleting it?

Name your text box. In the onClick() event, set the text to ‘’.

Probably worth checking if this is the first time the onClick() has been called, otherwise you could end up clearing your own text if you update, move away and then return

Russell

Even simpler than Lib and RussellM’s suggestions - use OnFocus and “this”:


<input type="text" value="Whatever" onFocus=javascript:this.value="">

Sorry, for some reason the hamsters split the word “javascript” up. Should be all one word.

But that will clear the box even if the user just tabs to it.

OnFocus should be better than OnClick for tabbing. Just testing it now…

IE: Yes
NS4.x: Yes
NS7: Yes
Mozilla (last year, dunno version number): Yes

So, “yes” across the board.