I could not find an answer for this. So I hope it's not redundant..
Have a simple form element:
<label>Email Address:</label>
<input type="text" onblur="validateEmail(this)" />
And I'm running a validation script to check whether this input value (onBlur) is valid. Works great!
Now.. what I'm trying to do is keep the script universal - so I do not have to rely on class names or IDs to make it work.
So what I want to know is how to take action on this field if the value is NOT an email address. Specifically, I want change the color of the label and put a red border on the field itself.
Here's the script that does not work:
var inputTextTest = field.value;
var filter = /^((\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*?)\s*;?\s*)+/;
if ( filter.test(inputTextTest) ) {
var name = field;
$(this).focus();
$(this).css("border","1px");
$(this).css("border-color","red");
} else {
$(this).css("border", "none");
}
I can see that my call to $(this) isn't working. So how do I take action on this particular field and keep the script totally universal (i.e., not dependent on specific classes or ID names)?
Thanks to all in advance for your help!