Solved

JQuery Validation Problem

Posted on 2013-06-25
3
213 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

10 Experts available now in Live!

Get 1:1 Help Now