Results 1 to 4 of 4

Thread: Search Textbox like Answers.com

  1. #1
    Join Date
    Dec 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Search Textbox like Answers.com

    Hi,

    I am trying to create a search textbox , such that when it is onblur, the textbox will show a bg image, while onfocus, it will be just empty blank bg.
    When there is text in the textbox, it will have no bg image when it is onblur.

    I am able to do it in this way.

    <input name="search" type="text" onblur="this.style.backgroundImage='url(images/random.gif)';this.style.backgroundPosition='center center';this.style.backgroundRepeat = 'no-repeat';" onfocus="this.style.background='yellow'"/>

    However, the problem come when there is text in the textbox. When it is onblur, the bg image will be back inside the textbox, which cover up the search term in the text box.

    One of the working example is from the answers.com
    http://www.answers.com/test
    When the textbox is empty, the image of "tell me about..." will be in the text box when it is onblur. However, when there is text in the textbox. the image will not be appear.

    How do I check if there is text in the textbox, and prevent it from loading the image when there is?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Eh? The "Tell me about" text on answers.com is next to the textbox, not in it.

    Code:
    onblur="if(this.value == '') { this.style.backgroundImage='url(images/random.gif)';this.style.backgroundPosition='center center';this.style.backgroundRepeat = 'no-repeat';}"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It is inside the text box actaully.

    Anyway, the code works great!


    thanks a lot!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's not... honestly
    I had to sample the attachment rather small to make the filesize acceptable to the forum, but you can still make out where the text is in relation to the textbox.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •