Hi all,
I am using barcode scanner. Once i scanned a barcode into a text box, i need a javascript which can auto copy to a textarea. Without users clicking any keyboard key or mouse to activate the event.
The following is my Javascript and HTML codes:
<input name="textA" id="textA" type="text" value="<%=request("textA"
%>" size="20" maxlength="6" onKeydown="checkEnter(this);"
<script language="JavaScript">
<!--
var ctr = 0;
var VArray = new Array();
function checkEnter(textEl) {
if(window.event.keyCode==13){
event.returnValue = false;
}
else {
copyText(document.form1.textA.value);
}
}
function copyText(strText) {
var currCopy = trim(document.form1.textA.value);
if (currCopy.length ==6) {
if (ctr == 0) {
VArray[ctr] = currCopy;
} else {
//check if the barcode exist in the array
for (var k=0; k<ctr; k++) {
if (VArray[k] == currCopy) {
alert("Duplicate barcode code being scanned."
;
document.form1.textA.value= "";
return false;
}
}
VArray[ctr] = currCopy;
}
// if no duplicate, shall copy into the TextArea
document.form1.lstbarcode.value += strText+"\n";
document.form1.texta.value = "";
ctr++;
} else {
alert("Please enter 6 alphanumerics for the texta."
;
}
return true;
}
//-->
</script>
I am using barcode scanner. Once i scanned a barcode into a text box, i need a javascript which can auto copy to a textarea. Without users clicking any keyboard key or mouse to activate the event.
The following is my Javascript and HTML codes:
<input name="textA" id="textA" type="text" value="<%=request("textA"
<script language="JavaScript">
<!--
var ctr = 0;
var VArray = new Array();
function checkEnter(textEl) {
if(window.event.keyCode==13){
event.returnValue = false;
}
else {
copyText(document.form1.textA.value);
}
}
function copyText(strText) {
var currCopy = trim(document.form1.textA.value);
if (currCopy.length ==6) {
if (ctr == 0) {
VArray[ctr] = currCopy;
} else {
//check if the barcode exist in the array
for (var k=0; k<ctr; k++) {
if (VArray[k] == currCopy) {
alert("Duplicate barcode code being scanned."
document.form1.textA.value= "";
return false;
}
}
VArray[ctr] = currCopy;
}
// if no duplicate, shall copy into the TextArea
document.form1.lstbarcode.value += strText+"\n";
document.form1.texta.value = "";
ctr++;
} else {
alert("Please enter 6 alphanumerics for the texta."
}
return true;
}
//-->
</script>