What is wrong with this statement?
message = $("#contact-form").find(".long-text");
if(message.val().length < 15)
{
message.css("border","2px solid red");
alert("Your message must be more than 15 character long");
}
I get message.val is not a function error in Firebug? What could be the reason?
NEW
OK, now my form won’t submit if I have more or less than 15 characters. Should I open a new question on this or should I continue on this one?
I have this inside:
$("#contact-form").submit(function(){
message = $("#contact-form").find(".long-text");
if(message.val().length < 15)
{
message.css("border","2px solid red");
alert("Your message must be more than 15 character long");
return false;
}
else {
Post form with Ajax ..
}
});
As you can see in the syntax highlighter, the quotes went bogus 🙂 There’s a doublequote missing.
Besides, the
val()only works oninputelements (input,select,textareaandbutton). If it is indeed not aninputelement, then rather usetext()instead. Further there’s no such function aslength(), you probably would like to use thelengthproperty.I recommend to go get yourself through some basic jQuery tutorials and/or to go get a jQuery book.