I’d like the text in the search box to disappear when the box is clicked in. Easy, right? I’ve found several how-to pieces online, and gotten it to work with at least two different methods. However, I found a [URL=“http://bytes.com/topic/html-css/answers/155272-making-default-entry-search-text-box-disappear-click”]rather snotty discussion of form semantics that made me wonder: what’s the right way to accomplish this, can I tighten up this code to be clean and tidy, and most importantly, can someone explain it to me so I can understand it? Forms tend to leave me confrazzled.
The site link’s above but here’s the code:
[highlight=“HTML 4.01 Strict”]<form method=“get” action=“http://www.google.com/search” id=“search”>
<div>
<div class=“qkinsearch-box”>
<label for=“mainsearchbox”>Search Site</label>
<input type=“hidden” name=“ps” value=“10”>
<input type=“text” size=“15” class=“search-field” name=“s” id=“mainsearchbox” value=“search amy’s site” onfocus=“if(this.value == ‘search amy’s site’) {this.value = ‘’;}” onblur=“if (this.value == ‘’) {this.value = ‘search amy’s site’;}”>
<input type=“submit” value=“” class=“search-go”>
</div>
</div>
</form>
Possibly relevant CSS:
```css
/*** search form ***/
form#search {
float: right;
width: 32em;
margin-top: -4.75em;
margin-right: .5em;
font-family: "Liberation Sans", "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
}
form#search input {
font-family: "Liberation Sans", "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
}
form#search label {
position:absolute;
left:-999em;
}
form#search input#mainsearchbox {
font-family: "Liberation Sans", "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
}
.qkinsearch-box {
background:url(../images/search/search-box.gif) no-repeat top left;
height: 26px;
padding: 5px 0 0 10px;
width: 165px;
margin-right: 20px;
float:right;
display:inline;
}
input.search-field {
float: left;
border:0;
margin:0;
font-family: Tahoma, Arial, sans-serif;
font-size: 12px;
padding: 3px 0px 1px 4px;
height:17px;
background: #fff url(../images/search/search-form.png) no-repeat 100% 0;
width: 123px;
color: #a8a8a8;
}
input.search-go {
float:left;
border:0;
margin:0;
padding:0;
margin-left: 7px;
height: 21px;
width: 21px;
background: url(../images/search/search-icon.png) no-repeat top left;
cursor: pointer;
}
input.search-go:hover {
background:url(../images/search/search-icon.png) no-repeat bottom left;
}
I’m quite sure there are some redundant and useless elements in both the HTML and CSS, but I’m not sure what should be left out, what should remain, and what should be edited.
Note: This search isn’t functional yet. I haven’t secured a URL for the client yet, and therefore haven’t put in for a Google search account for her. So those critical elements are definitely missing.