Clearing a default value in a search box with jQuery

Posted by james6848 on Stack Overflow See other posts from Stack Overflow or by james6848
Published on 2010-03-30T10:31:43Z Indexed on 2010/03/30 10:33 UTC
Read the original article Hit count: 169

Filed under:

Hi,

Can't seem to achieve this simple functionality! All I want is to clear a default search term in an input box when it is clicked. The following works up to a point but clears any other text entered, I would've thought resetting search_form_text should have solved this:

search_form_text = $('#block-search-0 #edit-search-block-form-l').attr('value');

if (search_form_text == 'Enter search keywords here') {

        $('#block-search-0 #edit-search-block-form-l').click(function() {           
            $('#block-search-0 #edit-search-block-form-l').attr('value', '');
            search_form_text = '';
        });

    }

Hmmmm... :)

© Stack Overflow or respective owner

Related posts about jQuery