There is a barcode scanner that displays the code KD-R411ED 105X0001 in one textfield. The goal is to automatically separate this code into two textfields - KD-R411ED in the first and 105X0001 in the second, all happening after scanning the barcode. At the moment, the program is still a work in progress.
You have the ability to achieve this functionality by making use of the code snippet below:
var barCode = 'KD-R411ED 105X0001';
var data = barCode.split(" ");
To access the separated values, you can utilize the following lines of code:
var product = data[0]; // outputs KD-R411ED
var serial = data[1]; // outputs 105X0001
Edit
Your current code looks like this:
<script type="text/javascript>
function addtext() {
var barCode = this.(text);
$("#model").change(function() {
barCode = $this.val();
var data = barCode.split("");
$("#model").val(data[0]);
$("#serial").val(data[1]);
});
};
</script>
Try modifying it to the following format:
<script type="text/javascript>
$(document).ready(function(){
$("#model").change(function() {
var data = $(this).val().split(" ");
$("#model").val(data[0]);
$("#serial").val(data[1]);
});
});
</script>