right to the point. Have this form:
<form action="/Home/AskQuestion" method="post" id="question">
<div class="name">
<label>Name</label><br>
<input type="text" class="name required">
</div>
<div class="email">
<label>Email</label><br>
<input type="text" class="email required">
</div>
<div class="subject clearleft"><label>Subject</label><br> <select name="GroupId" class="emailSubject required" id="SubmitAQuestionEmailSubject"><option value="0">Customer Service</option><option value="1">Parts Request</option><option value="2">Product Question</option><option value="3">GCRR</option></select></div>
<div class="question clearleft">
<label>Question</label><br>
<textarea cols="20" rows="2" class="required"></textarea>
</div>
<input type="submit" class="submit">
</form>
and this code:
$(document).ready(function(){ $("form").validate(); });
A google search for “jquery.validate example” gives me back all sorts of hits for a “working” sample just like this, which will prevent a form submission if any of the class=”required” fields are blank. The example on the jquery validate page works for me.
My form submits anyway when I leave a “required” input blank. What the hell am I doing wrong?
Edit: Lost some info that was originally in this post somehow…
I am including both the jquery (1.6.1) and jquery validation (1.6 from the file header) script files. Jquery is included before jquery.validation. I’ve verified with firebug that the scripts are being found, and I’m not able to see any errors either in firebug or in the Firefox error console.
Edit2:
Interestingly, replacing the $(“form”).validate() with this code seems to trigger validation, but again, only the first input in the form (name) is validated…
$(".submit").click(function (evt) {
if ($("form#question").validate().form()) {
alert("valid");
}
});
Are you loading both jQuery and the validate plugin script?
In case you want to be lazy:
UPDATE:
Each
inputvalue needs aname=""associated with it. The validation won’t work otherwise.