I am running a client side validation javascript which will submit a form via an ajax post after validating the data. Here is the javascript:
$(.button).click(function() {
$(.error).hide();
var name = $(:input.name).val();
if ((name == ) || (name.length < 4)){
$(label#nameErr).show();
$(:input.name).focus();
return false;
}
var email = $(:input.email).val();
if (email == ) {
$(label#emailErr).show();
$(:input.email).focus();
return false;
}
var phone = $(:input.phone).val();
if (phone == ) {
$(label#phoneErr).show();
$(:input.phone).focus();
return false;
}
var comment = $(#comments).val();
if ((!comment) || (comment > 100)) {
$(label#commentErr).show();
$(#comments).focus();
alert(hello);
return false;
}
var info = 'name:' + name + '&email:' + email + '&phone:' + phone + '&comment:' + comment;
var ajaxurl = '<?php echo admin_url(admin-ajax.php); ?>';
alert(info);
jQuery.ajax({
type:post,
dataType:json,
url: myAjax.ajaxurl,
data: {action: 'submit_data', info: info},
success: function(response) {
if (response.type == success) {
alert(success);
}
else {
alert(fail);
}
}
});
$(:input).val('');
return false;
});
The four input fields are three text inputs for name, email and phone and then one textarea for the comments/queries section. The problem is that if I leave the textarea blank or enter over 100 characters the script does not go into the if ((!comment) || (comment > 100))
statement. I am wondering if there is a different value that gets assigned to a textarea when it is blank that is stopping the code from seeing it as empty ?