Jump to content


Site Search


2 replies to this topic

#1 thedanphillips

    Young Padawan

  • Members
  • Pip
  • 8 posts

Posted 05 October 2009 - 02:57 PM

Ok, here's what I'm trying to do, I want to make a search engine for an Intranet site I'm making. I have it coded like this:

<input type="submit" value="" id="srchbtn" />
<input type="text" value="Search..." id="srchtext" />

What that does it creates a submit button with no value ( I set the width and height to an image I wanted to use for the button and floated it to the left of the text) and a text input field with "Search..." in it. What I want is so when people click into the text input area, the "Search..." dispappears and they can type. What I have now is so when I click to type, I have to backspace the "Search..." before I can enter a keyword.

I tried writing a JavaScript function for it using the "onClick" attribute of HTML, but I honestly don't know shit about JS besides how to do a "hello world!" app lol. So, does anyone have the time to help me out and point me in the right direction? I'd honestly perfer a thorough tutorial, by that I mean one that explains why this bracket is there and why I write this there and blah blah.

Thanks a lot!

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 05 October 2009 - 04:15 PM

onclick="if(this.value=='Search...'){this.value='';}" onblur="if(this.value==''){this.value='Search...';}"

Add that to the text input you want and it should do as you want. Pretty standard thing you could see on most sites by checking their source code. Actually, I got this from this very page from P2L's search box at the top there. It even goes the extra step to add it back if the field is blank when the user focuses away from it.

#3 thedanphillips

    Young Padawan

  • Members
  • Pip
  • 8 posts

Posted 08 October 2009 - 03:34 PM

Thanks! Didn't even think of that. Too busy trying to fix a float drop.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users