-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultValue.js
55 lines (44 loc) · 1.14 KB
/
DefaultValue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
jQuery.fn.DefaultValue = function(text){
return this.each(function(){
//Make sure we're dealing with text-based form fields
if(this.type != 'text' && this.type != 'password' && this.type != 'textarea'){
return;
}
//Store field reference
var fld_current=this;
//Set value initially if none are specified
if(this.value=='') {
this.value=text;
$(this).css( 'color', '#888' );
} else {
//Other value exists - ignore
//return;
}
//Remove values on focus
$(this).focus(function() {
if(this.value==text || this.value=='')
this.value='';
$(this).css( 'color', 'black' );
});
//Place values back on blur
$(this).blur(function() {
if(this.value==text || this.value==''){
if( this.value=='' ){
$(this).css( 'color', '#888' );
}
this.value=text;
}
});
//Capture parent form submission
//Remove field values that are still default
$(this).parents("form").each(function() {
//Bind parent form submit
$(this).submit(function() {
if(fld_current.value==text) {
fld_current.value='';
}
});
});
$(this).attr( 'default_value', text );
});
};