?
Solved

JQuery Validation Problem

Posted on 2013-06-25
3
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
kevp75 earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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