0

I am using PHP5...I need to use barcode scanner for some functionality. On scan of every barcode am fetching value from database which is already stored. I am using ajax for that. My problem is that am not getting which jquery event i have to use to achieve this?

I tried blur function. But I need to take curser out every time which may be inconvenient for user. I tried keyup event which is taking first number of barcode which is not usefull. Next i used this Jquery plugin which also taking first number of barcode.

In This link they advising to use .net drivers . but i am using PHP 5 /CakePHP 2.10. Please guide me with this.

ndm
  • 59,784
  • 9
  • 71
  • 110
Shashikala
  • 457
  • 1
  • 8
  • 25
  • 2
    I'm not 100% sure but i thnk that scanner automatically add an `Enter` keystroke to the end. maybe you could use key-up-event and check for the key-code of enter. Or you could check for a minimum-length of the input before querying. – wayneOS Mar 28 '18 at 06:39
  • @wayneOS yes you are right . ENTER is the event triggering after scan. And i referred https://stackoverflow.com/questions/895171/prevent-users-from-submitting-a-form-by-hitting-enter this . its working me fine now and your suggestion helped me a lot. Thank you – Shashikala Mar 28 '18 at 07:00

3 Answers3

0

You Should consult your barcode scanner manufacturer, The enter function can be remove

Gen
  • 43
  • 1
  • 1
  • 6
  • This should be a comment (which I know you can't do) but may get downvoted as a non-answer. – Nigel Ren Mar 28 '18 at 06:51
  • @gen if its the possibility is true then valid only when you use one scanner. But different user may use different scanner so not valid – Shashikala Mar 28 '18 at 06:58
0

With the assistance of @wayneOS ... I solved this as follows. Am posting it because it may be helpfull

 $("#myid").keydown(function (event) {
       if(event.keyCode == 13) {
       var myid= $("#myid").val();

        //Calling ajax
        $.ajax({
            type: "POST",
            data: {myid: myid},
            url: "<?php echo "myurl; ?>",
            success: function (data) {
            alert("success");                    
            },
            error: function () {
                alert("1st ajax error");
            }
        });
        $("#myid").val('');
        event.preventDefault();
        return false;
        }            
    });
Shashikala
  • 457
  • 1
  • 8
  • 25
0

I configured the scanners in a way, so it adds a tab at the end of a scan. After this you only need to check the characters on keyup. If it is a tab, trigger the function you want.

Bernhard
  • 1,852
  • 11
  • 19