3

I'm trying to simulate click event on some element using jQuery when click enter in some textbox:

$("input[id$=txtbox]").bind('keypress', function (e) {
    if (e.keyCode === 13) {
       SimulateClick();
    }
});

function SimulateClick()
{
    $("input[id$=btn]").trigger('click');
}

here is the HTML:

<asp:Button ID="btn" runat="server" OnClick="checkUserPass_Click" Style="display: none" />

its not working on firefox. any ideas or work arounds?

Arrabi
  • 3,718
  • 4
  • 26
  • 38

3 Answers3

2

Trigger won't work to simulate click event defined on onclick attribute on the input element.

You have to bind your function to the input in order trigger to work.

$("input[id$=btn]").bind('click', function() {
  alert("I am clicked :)");
});

And now, if you execute $("input[id$=btn]").trigger('click');. This will work.

Abdul Munim
  • 18,869
  • 8
  • 52
  • 61
  • 1
    but the click I want to simulate will fire a some function in code behind C#. btn is a runat server button. – Arrabi Nov 15 '11 at 08:49
0

try using a simple html tag instead of asp control. <input type="button" id="btn" style="display: none;" >

sepid esf
  • 1
  • 1
-4

This works on FF and other browsers, too.

$('input#btn').click();
esengineer
  • 9,514
  • 7
  • 45
  • 69