Reputation: 819
I simply want to check if the input from field and field1 is the same. but I'm not sure where my mistake is.
jQuery Code:
$(document).ready(function () {
$('#f').validate({
rules: {
field: {
nowhitespace: true,
minlength: 6,
required: true
},
field11: {
equalTo: "#field1",
required: true
}
},
messages: {
field: {
required: "required",
minlength: "min 6."
},
field11: {
required: "required",
equalTo: "same as field."
}
},
submitHandler: function (form) {
javascript:document.f.submit();
}
});
});
HTML:
<form name="f" action="/path/to/service" method="POST">
<table>
<tr>
<td><label for="field">Field</label>: </td>
<td>
<input class="field" class="pw" type='field' id="field" name='field' size="20" />
</td>
</tr>
<tr>
<td><label for="field1">field 1</label>: </td>
<td>
<input class="field" class="pw" type='field1' id="field1" name='field1' size="20" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan='2' align="center">
<input name="submit" type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
Can anybody see my mistake? thx for any help
Upvotes: 0
Views: 78
Reputation: 40639
Try rules
like,
rules: {
field: {
nowhitespace: true,
minlength: 6,
required: true
},
field11: {
equalTo: "#field",// Use "#field" in place of "#field1"
required: true
}
},
Also add id in your form tag as you used $('#f').validate({ like,
<form name="f" id="f" action="/path/to/service" method="POST">
Or try it without id like,
$('form[name="f"]').validate({
Read equalTo method
Upvotes: 1
Reputation: 337580
You have the equalTo
rule on field
set to #field1
- it will always be equal to itself. Secondly, in the rules you are setting field11
, yet the actual name is field1
. Try this instead:
field1: {
equalTo: "#field",
required: true
}
Upvotes: 0