JQuery validation using is() and multiple CSS classes
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-04-30T19:22:06Z
Indexed on
2010/04/30
19:27 UTC
Read the original article
Hit count: 111
Hi Folks, Trying to debug something that basically .trim()'s, .val()'s and .length's a textarea input as HTML below (truncated):
<form id="Kontaktanfrage" method="post" action="tests/testform/">
...
<textarea cols="50" rows="8" id="el_12" name="FORM[Kontaktanfrage][el_12]" title="Ihre Nachricht: *" class="textarea required"></textarea>
...
</form>
JavaScript:
function validateField(formId, fieldId) {
if (fieldId) {
var element = "form#"+formId+" input#"+fieldId;
var fieldValue = jQuery.trim(jQuery(element).val());
var fieldLength = fieldValue.length;
var fieldError = "";
if ($(element).is('.textarea.required') && fieldLength == 0) {
fieldError = "error message";
}
}
}
The above if
check is never true
.
Using JQuery: 1.4.1.
Having seen other examples online, I can't see what the difference should be. Feel free to test it in FireBug at (http://www.initiat.de/tests/testform/). Any help appreciated, can't see what I'm doing wrong.
© Stack Overflow or respective owner