tags:

views:

53

answers:

4

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.

A: 

i think you require to modify this line of code

var data = barCode.split("");

to

  var data = barCode.split(" ");

more detail about split : http://www.w3schools.com/jsref/jsref_split.asp

Pranay Rana
i've been change my code but still no response <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>
klox
A: 

I think you are missing the space, the line:

barCode.split("");

should be:

barCode.split(" ");
Sarfraz
it IS valid. Separates the text on characters.http://www.w3schools.com/jsref/jsref_split.asp
Danail
@Danail: It is the text, see the line: `var barCode = this.(text);`
Sarfraz
i've been change my code but still no response <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>
klox
check if the barCode is not empty with alert(barCode); also if space is there in between text in it.
Sarfraz
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
A: 

Not sure what values you have in the #model form field... and from the look of it, you are splitting on "" which is not a valid delimiter.

Make sure you are splitting it using the correct delimeter.

if your data in #model is abc def ghi then split it on a space (" "). if it is abc,def,ghi then split it on comma (",") or semicolon, etc. etc.

Jimmy Chandra
i've been change my code but still no response <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>
klox
try to make sure that the event is not triggering on when you do $("#model").val(data[0]). jQuery might have trigger the same event again. Did you get something like so... if the original value of #model field is A B, will you get A in #model and nothing in #serial as an end result? Is that your problem? If so, it's because the thing that I mentioned in this comment. If so, try to detect if there is a delimiter in the first place before executing the split logic.
Jimmy Chandra
A: 

$("#model").change(function() { var barcode; barCode=$("#model").val(); var data =barCode.split(" "); $("#model").val(data[0]); $("#serial").val(data[1]); }); this is the final answer...my program can run normally..thanks

klox