Default Text Disappear on click

How do have a default text value in the search text field that disappears when you click in the box?

Like this: http://www.istockphoto.com
petewinterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Try something like this.
<span id="search">
<form  class="search" name="search" action="npc_search.php" method="get">
<input class="search_input" type="text" name="str" value="search" onclick="return searchClear();" />
<input class="search_submit" type="submit" name="submit" value="go" onclick="return searchIsBlank();" />
</form>

Open in new window

Ray PaseurCommented:
Sorry about the spacing :-(
<script language="JavaScript">
<!--
function searchIsBlank() { value=document.forms['search'].elements['sp-q'].value;
if (( value == "" ) || ( value == "search")) {
	alert("Please enter at least one word in the search box.");
	document.forms['search'].elements['sp-q'].value = "";
	document.forms['search'].elements['sp-q'].focus();
	return false;
} else {
	return true;
}
}

function searchClear() { value=document.forms['search'].elements['sp-q'].value;
if (value == "search") {
	document.forms['search'].elements['sp-q'].value = "";
	document.forms['search'].elements['sp-q'].focus();
	return false;
} else {
	return true;
}
}

Open in new window

Ray PaseurCommented:
In the JavaScript, please change "sp-q" to "str" (or what ever name you use for your search string.  Best regards, ~Ray
SAMIR BHOGAYTATeam LeadCommented:
Hello, use this code

<FORM action="http://www.domain.com" method="post">
<INPUT type="text" size="25" value="Enter Your Default Text Here" onFocus="if(this.value == 'Enter Your Default Text Here') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Enter Your Default Text Here';}" />
<INPUT type=submit value=Submit>
</FORM>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petewinterAuthor Commented:
Many Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.