...

View Full Version : Insert line after barcode is submitted



sea4me
03-13-2009, 04:33 AM
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:

<!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 :o.

rangana
03-13-2009, 04:59 AM
Try:


<input id="barcode" name="barcode" onkeydown="setTimeout(insertbarcode,1000)" type="text" />

sea4me
03-13-2009, 05:23 AM
Thank you!!!!

rangana
03-13-2009, 05:35 AM
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:


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='';
}
}

sea4me
03-13-2009, 06:09 AM
lol yes I did modify my post because I figured it out :)


var barcodelength = document.getElementById("barcode").value.length;

if(barcodelength > 0){

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum