jQuery Default Search Value |
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
jQuery Default Search Value |
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. |
|
|