G
graphicsxp
Hi,
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).
In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......
Does anyone know why ?
Thanks
<asp:TextBox ID="txtJournalist" runat="server" onkeypress="fct(event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search..."
CausesValidation="False" />
<asp:TextBox ID="txtJournalist2" runat="server" onkeypress="fct(event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2" runat="server" Text="Search..."
CausesValidation="False" />
function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$txtJournalist')
{
alert('ctl00$cpBody$txtJournalist');
document.getElementById("ctl00_cpBody_btnAuthor").click();
}
else if (obj.name == 'ctl00$cpBody$txtJournalist2')
{
alert('ctl00$cpBody$txtJournalist2');
document.getElementById("ctl00_cpBody_btnAuthor2").click();
}
else if (obj.name == 'ctl00$cpBody$txtPublication')
{
alert('ctl00$cpBody$txtPublication');
document.getElementById("ctl00_cpBody_btnPublication").click();
}
return false;
}
else
return true;
}
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).
In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......
Does anyone know why ?
Thanks
<asp:TextBox ID="txtJournalist" runat="server" onkeypress="fct(event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search..."
CausesValidation="False" />
<asp:TextBox ID="txtJournalist2" runat="server" onkeypress="fct(event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2" runat="server" Text="Search..."
CausesValidation="False" />
function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$txtJournalist')
{
alert('ctl00$cpBody$txtJournalist');
document.getElementById("ctl00_cpBody_btnAuthor").click();
}
else if (obj.name == 'ctl00$cpBody$txtJournalist2')
{
alert('ctl00$cpBody$txtJournalist2');
document.getElementById("ctl00_cpBody_btnAuthor2").click();
}
else if (obj.name == 'ctl00$cpBody$txtPublication')
{
alert('ctl00$cpBody$txtPublication');
document.getElementById("ctl00_cpBody_btnPublication").click();
}
return false;
}
else
return true;
}