0

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>:&nbsp;&nbsp;</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>:&nbsp;&nbsp;</td>
            <td>
                <input class="field" class="pw" type='field1' id="field1" name='field1' size="20" />
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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
}

1 Comment

oh sorry yeah thats not the problem. just a replace mistake because i changed the names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.