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… 🙂
Try rearranging it like this:
This just prevents the user from searching for
'Enter search keywords here'specifically, but is that really an issue? Look up top on this page, type in “search”, click out, then click the box again…would a user ever even notice it? probably not 🙂The why it doesn’t work part:
$('#block-search-0 #edit-search-block-form-l').attr('value', '');will clear the value every time, you need an if to see if you actually want to clear 🙂