Solved

How to set focus on submit button of a login help web page?

Posted on 2008-06-11
8
351 Views
Last Modified: 2008-06-27
hi all,
i have a login help web page, it has a master page.
and in the content holder:
1.  there are two tables,
2. one table tblPwd is for "forgot your password",
3. and table tblLoginID is for "forgot your login id"
4. each table contains two text boxes: Login ID and Password
5. so there are two buttons, buttonPwd is for submitting "forgot your password", buttonLoginID is for submitting "forgot your login id"
6. when i click the txtPwd in tblLoginID, the buttonPwd in tblPwd is highlighted automatically. i think it means buttonPwd in tblPwd is set to default submit button by Asp.net.
7. Question is: how to make buttonLoginID in tblLoginID highlighted when i go to(eg. focus on, enter/type words) the textboxes in tblLoginID? and make buttonPwd in tblPwd highlighted when i go to(eg. focus on, enter/type words) the textboxes in tblPwd?

thanks a lot
viola
0
Comment
Question by:viola123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21765945
Through Javascript you can do this. Add a javascript function on the click or getfocus event of textbox. That javascript function will set the foucs on the required button.

Anurag
0
 
LVL 6

Author Comment

by:viola123
ID: 21766130
hi,
i am not a javascript expert, could you pls give me a sample code?

thanks
0
 
LVL 5

Expert Comment

by:Qaiser_Mehmood_Mughal
ID: 21766549
   <script language="javascript">
        function SetFocus()
        {
           btnSubmit.focus();
        }
    </script>

Call this method where ever you want to set the focus after the event.
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 6

Author Comment

by:viola123
ID: 21766788
hi,
it does not work for this case.
0
 
LVL 3

Expert Comment

by:Masoudgh
ID: 21768075
You can't use ".focus()" because when you click on any textboxes, the focus changes and you can't enter any text.
You can use one of the functions (I mean "WebForm_FireDefaultButton") in "WebForms.js" which is an embedded resource inside System.Web.dll.
So add the following codes to Page_Load.
Change the following names and correct them:  "TextBox1InTable1", "TextBox2InTable1", "TextBox1InTable2", "TextBox2InTable2", "ButtonNameInTable1" and "ButtonNameInTable2".

Now enjoy it... ;)
        ClientScript.RegisterClientScriptResource(typeof(Page), "WebForms.js");
        TextBox1InTable1.Attributes.Add("onkeypress", "javascript:return WebForm_FireDefaultButton(event, 'ButtonNameInTable1')");
        TextBox2InTable1.Attributes.Add("onkeypress", "javascript:return WebForm_FireDefaultButton(event, 'ButtonNameInTable1')");
        TextBox1InTable2.Attributes.Add("onkeypress", "javascript:return WebForm_FireDefaultButton(event, 'ButtonNameInTable2')");
        TextBox2InTable2.Attributes.Add("onkeypress", "javascript:return WebForm_FireDefaultButton(event, 'ButtonNameInTable2')");

Open in new window

0
 
LVL 3

Expert Comment

by:Masoudgh
ID: 21768179
I mentioned if you want to highlight the new button (change focus) you will not able to type immediately, so if it is important for you to change the face of active submit button, then change style and work on it.
0
 
LVL 6

Author Comment

by:viola123
ID: 21774835
hi,
it is not working properly.  when i click txtbox in table2, the button1 is still be highlighted.

thanks
0
 
LVL 6

Accepted Solution

by:
viola123 earned 0 total points
ID: 21774870
hi,
i used the following code to do the processing. but button1 is still be highlighted when i click textboxes in table 2.


txtBox_Pwd1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + BUTTON1.UniqueID + "').click();return false;}} else {return true}; ");
            txtBox_Email1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + BUTTON1.UniqueID + "').click();return false;}} else {return true}; ");
            txtBox_Email2.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + BUTTON2.UniqueID + "').click();return false;}} else {return true}; ");
            txtBox_Pwd2.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + BUTTON2.UniqueID + "').click();return false;}} else {return true}; ");

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question