views:

32

answers:

2

dear all..i've a textfield, it using barcode scanner for input data..after scan it shows KD-R411ED 105X0001... I'm successful separate them into two text field use ".change(function)"

$("#tags1").change(function() {
  var barcode;
  barCode=$("#tags1").val();
  var data=barCode.split(" ");
  $("#tags1").val(data[0]);
  $("#tags2").val(data[1]);
});

what i want is beside make them separate after ".change(function)" another script can read two character behind "KD-R411ED"..that is "ED"..this character can make a radiobutton which id="check1" are checked..

what's code which can combine with code above?

this my complete code..

$("#tags1").change(function() {
                                 var barcode;
                                 barCode=$("#tags1").val();
                                 var data=barCode.split(" ");
                                 $("#tags1").val(data[0]);
                                 $("#tags2").val(data[1]);

                                 var code = data[0].substr(data[0].length - 2); // suggested by Jan Willem B

                                 if (code =='UD')                                                                     $('#check1').attr('checked','checked');
                                                } else {
                                                        if (code == 'ED') {
                                                                        $('#check2').attr('checked','checked');
                                                }
                                                 }

and this the form

<input id="check1" type="radio" class="check" name="check" onclick="addtext()" value="U" />U
<input id="check2" type="radio" class="check" name="check" onclick="addtext_1()" value="E" />E

the radiobutton still not response

A: 

To read the last two characters:

var code = data[0].substr(data[0].length - 2);
alert(code);
Jan Willem B
how to read ED character if text like KD-R411H2EDT?
klox
A: 

did you mean,

$("#tags1").change(function() {
  var barcode;
  barCode=$("#tags1").val();
  var data=barCode.split(" ");
  $("#tags1").val(data[0]);
  $("#tags2").val(data[1]);

  var code = data[0].substr(data[0].length - 2); // suggested by Jan Willem B

  if (code == 'ED') {
     $('#check1').attr('checked','checked');
  }
});
Reigel
YUPZ...like that!!how if show JD?? can it like this?if (code == 'JD') { $('#check2').attr('checked','checked'); }
klox
yes... you can do that...
Reigel
how about this..it refers from Jan Willem B answer..how to read ED character if text like KD-R411H2EDT? may be need some manipulation in that answer??
klox