MasterUZ MasterUZ - 5 months ago 6x
Javascript Question

Validation doesn't check rules

I use the jQuery Validate plugin to check forms on website. Here is a piece of my HTML form for checking

<form id ="formCharacteristics" align="center">
<dt style="text-align:left; margin-left:120px;"><label for="cpuname">CPU name</label></dt>
<dd><input type="text" id="cpuname" placeholder="Intel 8086"></dd>
<div align="right" style="margin-right:30px">
<button id="buttonSubmitCharacteristics" type="button" onclick = "AddCPU()" >Done</button>
<button type="button" onclick="HideMessage()">Back</button>

And here is piece of JavaScript code, it invokes validation before Ajax posting

var form = $('#formCharacteristics');
var CPUname = $('input #cpuname');

Validation works properly on other forms, but on this form it doesn't check any rule. I don't use same form ID and input ID.

Here is code for specifing rules

$(document).ready(function() {
cpuname: {
required: true,
maxlength: 30,
minlength: 4



Your Code:

    rules: { 
        cpuname: { // <- this is the NAME attribute
            required: true, 
            maxlength: 30,

For the jQuery Validate plugin to work properly, your input must contain the same name as specified in the rules object...

<input type="text" name="cpuname" id="cpuname" ....