开发者

Simulating a click to submit a form in jQuery

Alright so I have a text field that will have a bar code scanned into said text field. It will search the database and return information in the form of a submit button. I am using this code to simulate a click on the submit button.

if($.browser.msie){
//simulate a click on the button
    $("#search").keyup(function (e) {
        if(e.keyCode == 13开发者_如何学C) {
          $('input:submit').click();
        }
     });
}

The problem with this code is that it takes all of the keystrokes and then clicks the button that many times. This submit will represent data that gets written into the database, so if the bar code was abc123 it would do this action 6 times, but I just need it to do it once. How do I fix this? My code works in FF and Chrome, but not IE, which is the one I need to get this to work in. Grrr I hate IE so much!


Why do you need to "click" that submit button? Why don't you just submit the form like:

$("#search").blur(function(){
   document.myform.submit();
});

Your barcode reader will do this for you.


Try to get code like this:

var keyCode = (window.event) ? e.which : e.keyCode;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜