Textbox onfocus content clear question

Discussion in 'HTML & Website Design' started by Grimmfang, Dec 12, 2011.

  1. #1
    <div style="margin-right: 10px;">
    		<input value="Search..." class="custom-search" type="text" name="q" size="25" maxlength="50"  />
    	</div>
    PHP:
    How can I make the search box clear the text upon user click?

    I want thinking something along the lines of onfocus=\"this.value=''\" />&nbsp;&nbsp but I got a PHP error as a result. Any help is always appreciated :)
     
    Grimmfang, Dec 12, 2011 IP
  2. Toycel

    Toycel Peon

    Messages:
    243
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    0
    #2
    Have you tried just onFocus=" "?

    If you are using your example for the onFocus then you are missing some quotes around this which is why the error may be occurring...
     
    Toycel, Dec 13, 2011 IP
  3. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #3
    use placeholder attribute

    <input type="text" name="q" size="25" maxlength="50" value="" placeholder="Search..." class="custom-search"  />
    Code (markup):
     
    yho_o, Dec 13, 2011 IP
  4. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #4
    The placeholder attribute works great, however doesn't show up in IE any solutions?
     
    Grimmfang, Dec 13, 2011 IP
  5. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #5
    javascript:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready( function(){
        $("#text").focus( function(){
            $(this).val="";
        });
    });
    </script>
    Code (markup):
    html:

     <input type="text" name="q" size="25" maxlength="50" value="" placeholder="Search..." class="custom-search" id="text"  />
    Code (markup):
     
    yho_o, Dec 15, 2011 IP