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!
LVL 5
allanau20Asked:
Who is Participating?
 
Luis PérezConnect With a Mentor Software 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.