Click here to Skip to main content
16,012,107 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to focus my textbox control using javascript:


Note:

My text Box Control is located in this following format,
How to focus my Text box control?

XML
<asp:CreateUserWizard ID="CreateUserWizard1">
<WizardSteps>

<asp:CreateUserWizardStep ID="CreateUserWizardStep1" >

<ContentTemplate>

                                 <asp:TextBox ID="UserName"/>

</ContentTemplate>

</asp:CreateUserWizardStep>

</WizardSteps>
</asp:CreateUserWizard>
Posted
Updated 14-Jun-12 23:01pm
v2

like this:

XML
<script>
    var txtBox = document.getElementById("UserName");
    if (txtBox != null )
    {
        txtBox.focus();
    }
</script>
 
Share this answer
 
Comments
Espen Harlinn 15-Jun-12 10:20am    
5'ed!
Manas Bhardwaj 15-Jun-12 10:51am    
thx!
XML
<script>
    var txtBox = document.getElementById("UserName");
    if (txtBox.value == "")
    {
        txtBox.focus();
    }
</script>
 
Share this answer
 

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