Log In · Register

 

Help Topic Rules and Requirements

For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.

This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources

Submission Guidelines

 
Reply to this topicStart new topic
jQuery Default Search Value
Mikeplyts
post Jul 4 2010, 01:29 AM
Post #1


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



So, I'm messing with jQuery right now, and I'm trying to do that ol' default search value trick. I have this so far:
CODE
$(function() {
    $('.text').click(function() {
        if ($('.text').val() == '') {
            $('.text').val('Search');
            $('.text').focus(function() {
                if ($('.text').val() == 'Search') {
                    $('.text').val('');
                }
            });
            $('.text').blur(function() {
                if ($('.text').val() == '') {
                    $('.text').val('Search');
                }
            });
        }
    });
});


It seems kind of glitchy, though. Like, it won't load the default value, but when you click on the input field, it loads the default value, and if you click out of it (blur), it stays the same, click again (focus) and it disappears, click out and it stays vanished. Any ideas? Simpler methods could also be useful.
 

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: