Solved

JQuery Validation Problem

Posted on 2013-06-25
3
214 Views
Last Modified: 2013-07-02
NuGet shows that the JQuery Validation in installed and I created the JQuery Validation in the View the way I thought it needed to be done but I cannot get it to run. All of the other fields have Validations so I only need to ensure that the user retypes the password correctly in the field with <input id="txtCheckPassword" type="text" />

Does anyone see the reason why the JQuery Validation will not run? (File attached below)
CreateAccountView.docx
0
Comment
Question by:AmbassadorSpock
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
kevp75 earned 500 total points
ID: 39278215
You are using the same field ID twice.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39278287
Here is the code in readable format, wrapped in [ code]...[ /code] as we prefer it

@model RescueFormsAdministration.Models.CreateAccountViewModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>
<script>
$.validator.setDefaults({
	submitHandler: function() { alert("submitted!"); }
});

$().ready(function() {
	// validate signup form on keyup and submit
    $("#CreateAccount").validate({
		rules: {
		    txtCheckPassword: {
				required: true,
				minlength: 5,
				equalTo: "#DataModel_Password"
			}
		},
		messages: {
			txtCheckPassword: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				equalTo: "Please enter the same password as above"
			}
		}
	});
});
</script>

@using (Html.BeginForm("Create", "Accounts", FormMethod.Post, new { id = "CreateAccount" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Account</legend>

		@Html.Partial("_CreateOrEdit", Model)

        <table style="width:100%">
    <!-- User Name and Password -->
    <tr>
        <td class="editor-label">
            @Html.Label("User Name")
        </td>
    </tr>
    <tr>
        <td class="editor-field">
            @Html.TextBoxFor(model => model.DataModel.UserName, new { style = "width:30%" })
            @Html.ValidationMessageFor(model => model.DataModel.UserName)
        </td>
    </tr>
    <tr>
        <td class="editor-label">
            @Html.Label("Password")
        </td>
    </tr>
    <tr>
        <td class="editor-field">
            @Html.TextBoxFor(model => model.DataModel.Password, new { style = "ModelStyle" })
            @Html.ValidationMessageFor(model => model.DataModel.Password)
        </td>
    </tr>
        <td>
            @Html.Label("Retype Password")
        </td>      
    <tr>
        <td>
            <input id="txtCheckPassword" type="text" />
        </td>
    </tr>
</table>
        <p>
            <input type="submit" value="Create" Name="btnSubmit" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39278290
Do you include the jQuery library in the head too?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now