Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Text Input Watermark

Question posted by: troberts (Newbie) on April 27th, 2008 07:59 AM
Hi
What I'm trying to achieve is a watermark on a search box (text input).
I've got it working fine (it displays an image, onfocus it shows no image) but when the user writes something then clicks somewhere else on the page it goes wrong. It displays the text plus the image (when I wrote the code I didn't think of this). I've tried a few other things but can't figure it out.
PS: I use CSS for the watermark (have tried JS). Any solution greatly appreciated.
CSS:
Expand|Select|Wrap|Line Numbers
  1. input
  2. {
  3. background-image: url('bkg.jpg');
  4. background-repeat: no-repeat;
  5. }
  6. input:focus
  7. {
  8. background-image: url('');
  9. }
  10. input:blur
  11. {
  12. background-image: url('');
  13. }


HTML:
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="d" size="34">
  2. <button type="submit" onclick="search_form()">Search</button>


Also (I'm doing this for my friend) I've put the page up. (I didn't do the layout!)
The link: http://www.webventures.com.au/search/form.html
Thanks
Tristan
jhardman's Avatar
jhardman
Moderator
2,263 Posts
May 14th, 2008
08:20 PM
#2

Re: Text Input Watermark
I'd suggest using straight JS. Place the watermark there to start, but use JS to remove the watermark onFocus and place the watermark (if needed) onChange. Let me know if this helps.

Jared

Reply
nanaveraa's Avatar
nanaveraa
Newbie
9 Posts
May 15th, 2008
01:08 PM
#3

Re: Text Input Watermark
Hello frnd,
I trying in css, but no result. So I m using in js. Pls try this code
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function imgfocus(){
  3. document.getElementById('ss').style.opacity='0.5';  
  4. }
  5. function imgblur(){
  6. document.getElementById('ss').style.opacity='100';  
  7. }
  8.  
  9. </script>
  10. <input id="ss" type="submit" onmouseover="imgfocus()" onmouseout="imgblur()";

Last edited by eWish : May 15th, 2008 at 02:16 PM. Reason: Fixed code tag
Reply
Reply
Not the answer you were looking for? Post your question . . .
189,799 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top HTML / CSS Forum Contributors