I have 2 asp text fields that I enabled jQuery to trigger a click on the server side linkbutton if I press enter in any of the 2 text fields. But this does not work, please help me explain where and what I am doing wrong. I need a solution that works in all major browsers [IE7,8,9], [Firefox 3.4], Safari [4,5].
Here is my code
<script language="javascript" type="text/javascript"> function GC_PostBack() { jQuery('#<%=lnkSubmitGiftCardNumber.ClientID%>').trigger("click"); }
and on the server side pn Page_Load, I bind this function to the onkeypress event from text fields.
if (!IsPostBack) { txtGiftCardNumber.Attributes.Add("onkeypress", "if(window.event.keyCode == 13) { GC_PostBack(); }"); txtGiftCardPin.Attributes.Add("onkeypress", "if(window.event.keyCode == 13) { GC_PostBack(); }"); }
I tried using .click (), not .trigger ("click"), but to no avail. Please, help!
Thanks.
source share