Friday, January 11, 2008

javascript function for invoking button click event

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>javascript function for invoking btnclick event</title>
<script language="javascript" type="text/javascript" >
function TrigButton()
{
if(window.event.keyCode == 13)
{
if(document.getElementById('txt').value.length > 0)
{
document.getElementById('bt').focus();
document.getElementById('bt').click();
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt" runat="server" Style="z-index: 105; left: 41px; position: absolute;
top: 141px" onkeydown="TrigButton()" ></asp:TextBox>
<asp:Button ID="bt" runat="server" Style="z-index: 107; left: 205px; position: absolute;
top: 142px" Text="Button" OnClientClick="javascript:alert('Button Triggered');" OnClick="bt_Click"/>
</div>
</form>
</body>
</html>

1 comment:

muthukumaran said...

good example. helped me to fix the problem. thanks