Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts

    Insert line after barcode is submitted

    I have this barcode scanner (it works just like a keyboard) and when I scan a barcode, it has this string inputted into my input text field.

    It usually takes 1 sec to scan and input it so would i be able to have say onkeypress to call that function and do that function 1 sec later?

    Should I use setTimeout(insertbarcode(),1000); in a function???

    Here is what I have so far:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">

    <
    head>
    <
    meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <
    title>Untitled 1</title>
    <
    script type="text/javascript">
    <!--
    function 
    insertbarcode()
    {
    var 
    barcode document.getElementById("barcode").value;
    var 
    code '<input type="text" name="barcode[]" value="' barcode '" disabled="disabled" />';
    code += "<br />";
    document.getElementById("content").innerHTML code document.getElementById("content").innerHTML;
    document.getElementById("barcode").value='';
    }
    -->
    </script>
    </head>

    <body>
    <input id="barcode" name="barcode" onkeydown="javascript:insertbarcode()" type="text" />
    <form action="#" method="post">
    <div id="content">
    </div>
    </form>
    </body>
    </html> 
    I made ^ PHP so that it would be colored (easier to read)

    When I put in the barcode, every one letter is on a new line so I was thinking of the 1 sec delay.

    BTW the barcode works exactly like a keyboard.....

    Can you guy help me??
    I'm just a noob .

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Try:
    Code:
    <input id="barcode" name="barcode" onkeydown="setTimeout(insertbarcode,1000)" type="text" />
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Thank you!!!!
    Last edited by sea4me; 03-13-2009 at 05:27 AM.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    You seemed to modify your post, anyway, you were asking on how to show only 1 field which is not empty. You could try this:
    Code:
    function insertbarcode() {
    	var barcode = document.getElementById("barcode").value;
    	if (barcode!='') {
    		var code = '<input type="text" name="barcode[]" value="' + barcode + '" disabled="disabled" />';
    		code += "<br />";
    		document.getElementById("content").innerHTML = code + document.getElementById("content").innerHTML;
    		document.getElementById("barcode").value='';
    	}
    }
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    lol yes I did modify my post because I figured it out

    PHP Code:
    var barcodelength document.getElementById("barcode").value.length;

    if(
    barcodelength 0){




  •  

    Posting Permissions

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