Page 1 of 1

Search box question

Posted: Thu Jul 03, 2008 6:38 pm
by cargo747
Moved to Client Side.

I have a basic php search box

Code: Select all

<form method="post" action="../search.php">
   <input type="hidden" name="posted" value="1"/>
    <input type="hidden" name="sprice" value=""/>
    <input class="search" type="text" name="stext" size="60" value="Search by Keyword or Part #"/>
<input type="image" name="Submit" src="../images/go.gif"/></form>
I would like to have the text disapear when the box is clicked. I can't seem to figure out how to make that work.

Thanks Cargo747

Re: Search box question

Posted: Thu Jul 03, 2008 10:20 pm
by tecktalkcm0391
Javascript:

Code: Select all

function clear(){
   documents.forms[0].stext.value = '';
}

Code: Select all

onclick="clear();"

Re: Search box question

Posted: Fri Jul 04, 2008 6:53 am
by VladSun
It's more apropriate to handle the "onfocus" event ...
Also it's better to use the HTML object itself:
[js]<input class="search" type="text" name="stext" size="60" value="Search by Keyword or Part #" onfocus="this.value=''"/>[/js]

Re: Search box question

Posted: Fri Jul 04, 2008 2:54 pm
by tecktalkcm0391
True. I forgot about using onFocus, and I'm just used to making functions, but that is easier.

Re: Search box question

Posted: Sat Jul 05, 2008 1:54 pm
by JellyFish
Yes but if the user accedently loses focus when they typed something in the search box, they will lose what they typed when they give focus back to the search box again.

The solution to this is:

Code: Select all

 
<input class="search" type="text" name="stext" size="60" value="Search by Keyword or Part #" onfocus="if (this.value == 'Search by Keyword or Part #') { this.value = ''; }" onblur="if (this.value == '') { this.value = 'Search by Keyword or Part #'; }"/>
 

Re: Search box question

Posted: Tue Jul 08, 2008 12:46 pm
by Ollie Saunders

Code: Select all

<form method="post" action="../search.php">
a search is a GET operation make sure you use method="get"