form field clearing script
I have the following code that I'm using to cycle through each element in a form field, and clear whatever text is in it. If the user clicks out of the field without typing anything then the script is supposed to return to whatever value it started with (e.g. "Enter your name..."). If the user does type something, then it stays in the field even when they click out of it:
- $(document).ready(function() {
- count = 0;
- fieldVal = [];
- fieldFocus = 0;
- $('#frm-quick input[type="text"], #frm-quick textarea').each(function() {
- fieldVal[count] = ($(this).val());
- $(this).focus(function() {
- if (fieldFocus == 0) {
- $(this).val('');
- }
- })
- $(this).keydown(function() {
- fieldFocus = 1;
- })
- (function(count){
- $(this).blur(function() {
- if (fieldFocus == 0) {
- $(this).val(fieldVal[count]);
- }
- })
- })(count);
- count++;
- })
- })
But it keeps resulting in this error and I have no idea why!
Error: $(this).keydown(function () {fieldFocus = 1;}) is not a function
Source File: file:///Users/pealo86/Documents/design/resource/code/script/frm-field-clear.js
Line: 19