• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

Web Pages: How To Set Focus on Textbox

Hi Experts!

This is ASP.NET 4.0 web pages (Razor) question; how do you set focus on the Username textbox?

<form method="post" action="">
<div class="formStyle01">
    <div class="row">
        <div class="label">
            <label for="username">
                Username:</label></div>
        <div class="input">
            <input type="text" id="username" name="username" value="@username" title="Username" @if (!usernameErrorMessage.IsEmpty())
                                                                                                {<text>class="input-validation-error"</text>} />
            @* Write any username validation errors to the page *@
            @if (!usernameErrorMessage.IsEmpty())
            {
                <label for="username" class="field-validation-error">
                    @usernameErrorMessage
                </label>
            }</div>
    </div>

..

When the page loads up we want the focus on the Username textbox.

TIA!
0
allanau20
Asked:
allanau20
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
Place this into the HEAD section of the page:

<script type="text/javascript">
    window.onload = function() {
        document.getElementById('username').focus();
    }
</script>

Hope that helps.
0
 
allanau20Author Commented:
wow; u da best. ThankS!
0
 
Prafulla MaharjanCommented:
<input type="text" tabindex="1" name="textfield" />

it may help u
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now