Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:07:14+00:00 2026-06-05T20:07:14+00:00

In my MVC4 app, I’m trying to create a client side validator for some

  • 0

In my MVC4 app, I’m trying to create a client side validator for some textboxes in a form. The form is contained in the Register.cshtml view (this view is automatically created by VS2010 when i make a new MVC4 with formsauthentication project).

The form already implements validation on Submit button, but I want a validator that acts as soon as focus leaves the textbox – should show me an inline error just next to the textbox, with a red font. if it validated ok, it should again show the message ‘ok’.

The problem: The .js validator doesn’t work. Firebug says:

$document is not defined.
$document.ready(

I also tried alert(), if i place it outside the document.ready function, it pops. when inside, it doesnt pop.
Code for registerForm.js:

$document.ready(
function () 
{
    $('#registration form').validate
    (
        {
            rules: 
            {
                UserName: { required: true }
            },
            success: function (label) 
            {
                label.Text('OK!').addClass('IsInputValid');
            }
        }
    )
}
);

The bundle that adds this javascript is as follows:

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/registerForm.js",
                    "~/Scripts/jquery.validate*"));

Finally, the view:

<div id="registration">
@using (Html.BeginForm()) {
@Html.ValidationSummary()

<fieldset>
    <legend>Registration Form</legend>
    <ol>
        <li>
            @Html.LabelFor(m => m.UserName)
            @Html.TextBoxFor(m => m.UserName)
        </li>
        <li>
            @Html.LabelFor(m => m.Email) 
            @Html.TextBoxFor(m => m.Email)
        </li>
        <li>
            @Html.LabelFor(m => m.Password)
            @Html.PasswordFor(m => m.Password)
        </li>
        <li>
            @Html.LabelFor(m => m.ConfirmPassword)
            @Html.PasswordFor(m => m.ConfirmPassword)
        </li>
    </ol>
    <input type="submit" value="Register" />
</fieldset>
 }
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

What could prevent the js from working?
I’ve already spent about 5hours trying to figure this out. Please let me know if you have any suggestions,

Regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:07:15+00:00Added an answer on June 5, 2026 at 8:07 pm
     @Html.TextBoxFor(m => m.UserName, new { @class = "required" })
    

    No need for JS here. And what everyone else is saying about $document not being the correct syntax, unless you have var $document = $(document) defined somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed MVC4 side-by-side with MVC3. When I create a new MVC4 web app
I'm trying to create an ImagesController in MVC4 like this But I keep getting
I am trying to develop a simple sample mobile web app using MVC4, to
I created a mvc4 web app. with razor view engine. There are Layout page
Just finished up my first mvc4 app. Everything is working great until I deploy
I have an ASP.NET MVC4 app which uses DotNetOpenAuth 4.0.1 to authenticate users with
I am creating a MVC4 application and I have got some troubles when I
So I'm about to create my first SPA project using .NET MVC4. But I
In a ASP.NET MVC 4 app I have a view with a paged list
I am trying to create a web site by using the html5 input controls.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.