# HTML Text Box

**URL:** <https://boards.straightdope.com/t/html-text-box/137889>\
**Category:** Factual Questions\
**Created:** [November 21, 2002, 6:50am UTC](https://boards.straightdope.com/t/html-text-box/137889 "2002-11-21T06:50:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duderdude2](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Duderdude2](https://boards.straightdope.com/u/Duderdude2)\
**Post date:** [November 21, 2002, 6:50am UTC](https://boards.straightdope.com/t/html-text-box/137889/1 "2002-11-21T06:50:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [November 21, 2002, 7:02am UTC](https://boards.straightdope.com/t/html-text-box/137889/2 "2002-11-21T07:02:12Z")

</div>

[http://wss.hypermart.net/html/html5.html](http://wss.hypermart.net/html/html5.html)

```auto

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

```

`value’ holds the default text.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [November 21, 2002, 7:03am UTC](https://boards.straightdope.com/t/html-text-box/137889/3 "2002-11-21T07:03:52Z")

</div>

Just for completeness, the text area:

```auto

<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.

---

<div class="post-metadata">

**Author:** ![Duderdude2](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Duderdude2](https://boards.straightdope.com/u/Duderdude2)\
**Post date:** [November 21, 2002, 7:05am UTC](https://boards.straightdope.com/t/html-text-box/137889/4 "2002-11-21T07:05:24Z")

</div>

Many Thanks!

---

<div class="post-metadata">

**Author:** ![Duderdude2](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Duderdude2](https://boards.straightdope.com/u/Duderdude2)\
**Post date:** [November 21, 2002, 7:29am UTC](https://boards.straightdope.com/t/html-text-box/137889/5 "2002-11-21T07:29:12Z")

</div>

Ooh, another question 😉

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?

---

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [November 21, 2002, 11:28am UTC](https://boards.straightdope.com/t/html-text-box/137889/6 "2002-11-21T11:28:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RussellM](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@RussellM](https://boards.straightdope.com/u/RussellM)\
**Post date:** [November 21, 2002, 11:44am UTC](https://boards.straightdope.com/t/html-text-box/137889/7 "2002-11-21T11:44:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)\
**Post date:** [November 21, 2002, 12:05pm UTC](https://boards.straightdope.com/t/html-text-box/137889/8 "2002-11-21T12:05:13Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

**Author:** ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)\
**Post date:** [November 21, 2002, 12:06pm UTC](https://boards.straightdope.com/t/html-text-box/137889/9 "2002-11-21T12:06:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [November 21, 2002, 2:55pm UTC](https://boards.straightdope.com/t/html-text-box/137889/10 "2002-11-21T14:55:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)\
**Post date:** [November 21, 2002, 3:00pm UTC](https://boards.straightdope.com/t/html-text-box/137889/11 "2002-11-21T15:00:47Z")

</div>

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.
