Link to home
Create AccountLog in
Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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

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

In the JavaScript, please change "sp-q" to "str" (or what ever name you use for your search string.  Best regards, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Pete Winter

ASKER

Many Thanks