jQuery .blur() form problem...help!
Hey guys,
I'm either having a dumb moment here, or I just can't find the answer, but I've written a script using jQuery that takes the elements of my form, checks to see if the default value is currently displayed on focus, if so the field is set to blank.
My problem is on blur. I want to loop through my default value array, find the name that corresponds to the input name, and add the default value to the input field.
Hopefully this makes sense to you guys, I've attached the code below:
- var defaults = {
- 'name' : 'Enter your name..',
- 'email' : 'Your e-mail address so I can reply..',
- 'website' : 'Your existing website (optional)',
- 'subject' : 'The subject of your message..',
- 'message' : 'Your message..'
- };
- $("input, select, textarea").focus(function() {
-
- var val = $(this);
-
- $.each(defaults, function(key, value) {
- if (val.val() == value || val.val() == "") {
- val.val("");
- return false;
- }
- });
- });
- $("input, select, textarea").blur(function() {
-
- var val = $(this);
- $.each(defaults, function(key, value) {
- if (val.val() == "") {
- //what do i write?!
- }
- });
- });
Any help is appreciated.