P
psion
Hi,
I am trying to set focus to a specific button in a server form when
typing in a specific text box and pressing enter.
For example, pressing enter in the search box at the top of the page
is to activate the submit search button next to it.
The login text box below it is to submit the login button when enter
is pressed.
The following code works in firefox 3, opera 9, and safari 3. IE 7 and
8 both have problems.
In IE, whenever a text box is clicked, and enter is pressed, the
correct button is fired. However, when I begin typing in that text
box, the top most button is fired.
The code I am using is below.
In the .aspx page, I have:
*************************************
<script language="javascript">
<!--
//FOCUSING
var toSubmit = "btnLogin";
function setSubmit(x){
if (x==1){
toSubmit = 'btnLogin';
}else if (x==2){
toSubmit = 'btn_tn_search';
}else{
toSubmit = 'none';
}
}
function goSubmit(){
if (toSubmit != 'none')
document.getElementById(toSubmit).click();
return false;
}
//-->
</script>
<body id="body1" runat="server" onkeydown="if(event.keyCode == 13)
{goSubmit();}">
*************************************
in the code behind class, I have:
*************************************
Me.txtUser.Attributes.Add("onfocus", "javascript:setSubmit(1);")
Me.txtSearch.Attributes.Add("onfocus", "javascript:setSubmit(2);")
*************************************
Is there an easier way to accomplish this task?
Is there an error in the code that causes the IE behavior?
Thank you in advance,
Krzysztof
I am trying to set focus to a specific button in a server form when
typing in a specific text box and pressing enter.
For example, pressing enter in the search box at the top of the page
is to activate the submit search button next to it.
The login text box below it is to submit the login button when enter
is pressed.
The following code works in firefox 3, opera 9, and safari 3. IE 7 and
8 both have problems.
In IE, whenever a text box is clicked, and enter is pressed, the
correct button is fired. However, when I begin typing in that text
box, the top most button is fired.
The code I am using is below.
In the .aspx page, I have:
*************************************
<script language="javascript">
<!--
//FOCUSING
var toSubmit = "btnLogin";
function setSubmit(x){
if (x==1){
toSubmit = 'btnLogin';
}else if (x==2){
toSubmit = 'btn_tn_search';
}else{
toSubmit = 'none';
}
}
function goSubmit(){
if (toSubmit != 'none')
document.getElementById(toSubmit).click();
return false;
}
//-->
</script>
<body id="body1" runat="server" onkeydown="if(event.keyCode == 13)
{goSubmit();}">
*************************************
in the code behind class, I have:
*************************************
Me.txtUser.Attributes.Add("onfocus", "javascript:setSubmit(1);")
Me.txtSearch.Attributes.Add("onfocus", "javascript:setSubmit(2);")
*************************************
Is there an easier way to accomplish this task?
Is there an error in the code that causes the IE behavior?
Thank you in advance,
Krzysztof