PDA

View Full Version : Input text in search box pre-search



o0bago0ba
02-12-2007, 08:36 PM
is there any way to do this?
you know, the kinda thing where the word 'search' is in the input field prior to the user clicking in this field to enter a search?
thanks in advance!
:)

wrensoft
02-12-2007, 08:55 PM
To set the field value you can use some HTML.
<input type="text" name="zoom_query" size="10" value="Your text here">

But the real trick if clearing the field when the user clicks on it to enter their own search word and restoring the value if they don't enter anything.



<script type="text/javascript">
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}
</script>

<input type="text" name="zoom_query" size="10" value="Your text"
onclick=”clickclear(this, 'Your text')” onblur=”clickrecall(this,'Your text')” />

o0bago0ba
02-12-2007, 09:06 PM
Many thanks - great product by the way :)

samuelmaxton
08-16-2011, 05:48 PM
Doesn't the input have to be in a "form" to work properly? I can't get this javascript to work on my page so that the field appears with default text and disappears/reappears on user action. I just copied it from above. Here's my page:

<html>
<head>
<title>You have reached a random place</title>
<meta name="description" content="dogs and other farm animals"/>
<meta name="keywords" content="albert,einstein,physics" />

<script type="text/javascript">
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == “”) {
thisfield.value = defaulttext;
}
}
</script>
</head>

<form method="get" action="http://www.jessiewilliams.com/search/search.php">
<input type="text" name="zoom_query" size="10" value="Your text"
onclick=”clickclear(this, ‘Your text’)” onblur=”clickrecall(this,’Your text’)”/>
<input type="submit" value="Click and See"/>
</form>

<h1>This is a Test</h1>

<body style="background-color:yellow;">

<p>blah blah</p>
<br />

</body>
</html>

wrensoft
08-17-2011, 01:06 AM
This question was answered twice via E-mail. Your HTML is invalid.

For example, your <form> tag is between the <head> and < body> tag. Which isn't valid HTML. Nor is the use of reverse quotes, like in ‘Your text’

moblieapps
10-31-2011, 02:12 PM
I love finding answers to my questions already posted. Thanks guys!