views:

150

answers:

3

hello...i have a problem with my project..i want to use barcode scanner for input data to textfield (i'm using jquery). this barcode scanner read serial number and model name of each product..but after scan, serial number and model name appear in one textfield. how to make them appear separately into different text field..first textfield for serial number and second textfield for model name...

is there some code to make it??use ajax,javascript or something else??

A: 

Some barcode readers let you program the output sequence.
Depending of the brand you have a series of prefixes or sufixes to add to the output.
For the computer itself, the barcode reader is nothing more than a keyboard.

If you need to get rid of the serial number an model, in the manual you should have instructions to modify the output sequense.
If you need this data, you could use one of the many jquery input mask pugins to acomplish what you whant.
Also, it's possible that you will get one or two additional characters along with re reading, those are for differentiate the barcode type (EAN, UPC, etc), you can also disable those.

The Disintegrator
this barcode scanner will show KD-R411ED 105X0001 inside one textfield...i want it become KD-R411ED in first text field and 105X0001 in other textfield...all automatically separate into two textfield after scan the barcode... but for actually it appear in one textfield...this program is under progress..
klox
Use onChange to monitor the textfield. When you see that the last character is an enter, use split (like reigel said) and finally $("#serial").val(serial); $("product").val(product);
The Disintegrator
after i've been modified code this program still can't seperate...why?
klox
Post your code so we can take a look at it.The form and the javascript
The Disintegrator
<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>
klox
sorry..this one my form <td width="300"><label for="tag">Model</label></td><td><td width="10">:</td> </td> <td> <td> <td width="450" align="left"> <input type="text" id="tags1" name="model"> </td> </td> </td> </tr> <tr> <td width="300"><label for="tag">Serial Number</label></td><td><td width="10">:</td></td><td><td> <td width="450" align="left"><input type="text" id="tags2" name="serial" ></td></td></tr>
klox
+4  A: 

this barcode scanner will show KD-R411ED 105X0001 inside one textfield...i want it become KD-R411ED in first text field and 105X0001 in other textfield...all automatically separate into two textfield after scan the barcode... but for actually it appear in one textfield...this program is under progress...

you can do this...

var barCode = 'KD-R411ED 105X0001';
var data = barCode.split(" ");

you can access data this way...

var product = data[0]; // output KD-R411ED
var serial = data[1]; // output 105X0001

edit


your code:

<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 this:

 <script type="text/javascript"> 

    $(document).ready(function(){

       $("#model").change(function() {  
           var data = $(this).val().split(" "); // not the space in .split(" ")
           $("#model").val(data[0]); 
           $("#serial").val(data[1]); 
       });

     });

 </script>
Reigel
ok thanks..i'll try it.
klox
i've been modified the code like below<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>but..still not separate..please help.
klox
please see edit if it helps...
Reigel
<script type="text/javascript"> $("#model").change(function() { var barcode; barCode=$("#model").val(); var data =barCode.split(" "); $("#model").val(data[0]); $("#serial").val(data[1]); }); </script>this is the final answer...my program can run normally..thanks
klox
You can accept this answer now... ;) this is how stackoverflow works.. ;)
Reigel
oh...okey!! i just know.thanks a lot
klox
A: 
 <script type="text/javascript">
     $("#model").change(function() { 
                                    var barcode; 
                                    barCode=$("#model").val();
                                    var data =barCode.split(" ");
                                    $("#model").val(data[0]);
                                    $("#serial").val(data[1]);
                                  });
 </script>

this is the final answer...my program can run normally..thanks

klox
If you used someone else's answer (eg Reigel's answer), you should mark it as accepted if it gave you the solution. Use the 'tick' mark on the left-hand side of the answer.
richsage
thanks for u're suggestion..
klox
it feels like I did not do any help at all...
Reigel
i learned a lot from you
klox