Click here to Skip to main content
16,004,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am having logon page once user enter inside this page cursor must be Username Text box
How to focus this .
am using MVC3 and would like to do this with jQuery



please anyone help
Posted

1 solution

Take a look at this:
How do I set focus to a text box Html.TextBoxFor - mvc 2[^]

or try this:
@model MvcApplication1.Models.LogOnModel

@{
    ViewBag.Title = "Log On";
}

<script type="text/javascript">
    $(function () { $('#txtUserName').focus(); });
</script>

<h2>Log On</h2>
<p>
    Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account.
</p>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")

@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName, new { maxlength = 23, id = "txtUserName"})
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
}

It has been tested and works.
 
Share this answer
 
v3
Comments
kimberly wind 5-Jun-12 8:17am    
@model Etrade_MVC3.Models.FormLogOn
@{
ViewBag.Title = "LogOn";
}
<script type="text/javascript">

$(function () { $('#txtUserName').focus(); });

</script>


<div>
<img src="@Url.Content("~/Images/banner.jpg")" width="1000" height="334" alt="Banner" />
</div><br />
<div id="Landing">
@using (Html.BeginForm("LogOn", "User", FormMethod.Post, new { id = "Landing" }))
{
<div class="homediv">
@Html.TextBoxFor(m => m.UserName, new { maxlength = 23, id = "txtUserName", @Value = "UserName" })
@Html.PasswordFor(m => m.Password, new { maxlength = 23, minlength = 6, id = "txtPassword", @Value = "Password" })
<label class="label3">
@Html.CheckBoxFor(m => m.RememberMe, new { id = "checkbox", @class = "checkbox" })
RememberMe
<br />
<br />
@Html.ActionLink("Forgot Password?", "../User/ForgotPassword")
</label>
</div>

like this i used to jQuery but its not working :(
Nikfazan 5-Jun-12 8:39am    
Use the code on Solution 1, It has been tested and works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900