Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Thanked 0 Times in 0 Posts

    Need help in input data from barcode to textbox then move cursor to next textbox


    I need to input data in my textbox by scanning barcode then the data will input to textbox then the cursor focus move to next textbox until it goes to last textbox then save data.

    How is it possible?

    I'm not familiar with ajax :(

    I am right that ajax code will do it?

    here is my sample code:

       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    if (!$con) {
        echo 'failed';
    mysql_select_db("mes", $con);
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <script type="text/javascript" > 
    // this variable says how many characters you allow 
    // to input in each textbox 
    var input_size = 3; 
    function checkTextBox( ct ) 
        var tab = ct.tabIndex; 
             if ( ct.value.length == input_size ) 
                for(i=0; i<document.barcode.elements.length; i++) 
                          if( document.barcode.elements[i].tabIndex == (tab+1) ) 
    <body onLoad="document.barcode.code_read_box1.focus();"> 
    <form name="barcode" > 
    <input type="text" tabindex="1" id="code_read_box1" value="" onKeyPress="checkTextBox(this);"/><br/> 
    <input type="text" tabindex="2" id="code_read_box2" value="" onKeyPress="checkTextBox(this);"/><br/> 
    <input type="text" tabindex="3" id="code_read_box3" value="" onKeyPress="checkTextBox(this);"/><br/> 
    <input type="text" tabindex="4" id="code_read_box4" value="" onKeyPress="checkTextBox(this);"/><br/> 
    <input type="text" tabindex="5" id="code_read_box5" value="" onKeyPress="checkTextBox(this);"/><br/> 
    <input type="text" tabindex="6" id="code_read_box6" value="" onKeyPress="checkTextBox(this);"/><br/> 
    In that code I use javascript, but the problem in my code is it move to another textbox after i input 3 characters but it did not what I want because i need to use barcode instead of keyboard.

    I hope somebody can help me.

    Thank you so much

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 568 Times in 561 Posts
    Usually with the barcode scanner there's a driver that enables you to "scan the barcode into the currently active textbox". It has nothing to do with Javascript in the first place. The driver does the scanning and pastes the result into the textbox.

    Beyond that there is no easy cross browser way to detect paste events (at least last time I checked). So a workaround would be to have a setInterval function checking the textbox for a changed value.
    var myTextbox = document.getElementById('mytextbox');
    var oldValue = myTextbox.value;
    var myInterval = window.setInterval(function() {
       var newValue = myTextbox.value;
       if(oldValue != newValue) {
    }, 100);
    You should omit the "clearInterval" part if you want to detect more than one change of the textbox

  • Users who have thanked devnull69 for this post:

    newphpcoder (05-03-2012)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts