How to instantley delete content in search field.

Discussion in 'PHP' started by Bulldog-Designs, Nov 8, 2006.

  1. #1
    This may sound confusing but here it goes. I have a small search on my site, within this little search box i have some content, i.e. "search here!" . When you use this you have to first delete "Search Here!" And then input what you want to search for.

    I want it so when you click the box all of the content instantley disappears. make sense?

    Anyone know how to do this?
     
    Bulldog-Designs, Nov 8, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you dont mind using javascript this will work. This is directly from one of my sites, so you can just change the class, name and other fields as you need. Make sure the onFocus and onBlur values matche the actual value in the form tag. Let me know if you need help.
    
    <input class="sp2_field" type="text"
    onfocus="if ( this.value == ' Search The Website ' ) this.value = '';" 
    onblur="if ( this.value == '' ) this.value = ' Search The Website ';" 
    id="q" maxlength="255" name="q" value=" Search The Website " />
    
    Code (markup):
     
    jestep, Nov 8, 2006 IP
  3. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I believe that I understand what you mean. The technology you need is javascript. The code will be something like:

    <input type='text' name='search' onFocus='document.this_form.search = "";' />
    Code (markup):
    The emphasis is on the 'something like', whenever I need to produce javascript code I need to consult a reference book and I don't have it to hand at the moment.
     
    streety, Nov 8, 2006 IP
  4. schmidte

    schmidte Peon

    Messages:
    345
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
  5. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I was actually going to post the code used in the login box for this forum

    <input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" />
    Code (markup):
    But actually the code posted by jestep would be my preference. The onblur is a really nice feature.
     
    streety, Nov 8, 2006 IP
  6. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Oki heres what I have... Can you show me exactly where I need to put this stuff?
     
    Bulldog-Designs, Nov 8, 2006 IP
  7. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #7
    
    <input type="text" size="62" 
    onfocus="if ( this.value == 'Hi' ) this.value = '';" 
    onblur="if ( this.value == '' ) this.value = 'Hi';"
     id="q" name="q" maxlength="255" value="Hi" style="color: #CC0000" />
    
    Code (markup):
    You dont need the id= field or maxlength or anything unless you want them.
     
    jestep, Nov 8, 2006 IP
  8. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Thank you, I will give it a try!
     
    Bulldog-Designs, Nov 8, 2006 IP
  9. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #9
    works great, thanks again
     
    Bulldog-Designs, Nov 8, 2006 IP