show data at DIV after use .focus() in jquery

依然范特西╮ 提交于 2020-01-06 03:56:25

问题


Lets say i have a form like:

<select id="model"/>
<input type="text" id="serial"/>
<label>Packing <div id="packing" name="packing"></div></label>
<br/>
<input id="pack1" type="radio" class="pack" name="pack" value="OK" />OK
<input id="pack2" type="radio" class="pack" name="pack" value="NG" />NG
i'm using barcode scanner for input `serial`, i want do like this:
  1. choose model at dropdown list
  2. after model choosen, set focus into #serial so it can makes data show at textfield
  3. data after scan show inside textfield
  4. after textfield are filled, show some data from DB inside the DIV

this is what i have got:

$("#model").click(function() {
          var data=$("#model").val();
          $("submit input:text.eq(0)").focus();
          var str=data;
          var matches=str.match(/[TEJUG2]\D*D/i);

          $.ajax({
                   type:"post",
                   url:"process1.php",
                   data:"packing="+matches+"&action=packcond",
                   cache:false,
                   async:false,
                   success: function(res){
                                    $('#value').replaceWith(
                                          "<div id='value'><h6>" + res + "</h6></div>"
                                          );
                                    }
                   });
          });

but i think this not resolve the problem.can you help me? :-)


回答1:


$("#model").change(function() {
                  $('#serial').focus();
                  });

$('#serial').change(function(){
                  var data=$("#model").val();
                  var str=data;
                  var matches=str.match(/[TEJUG2]\D*D/i);

                  $.ajax({
                          type:"post",
                          url:"process1.php",
                          data:"packing="+matches+"&action=packcond",
                          cache:false,
                          async:false,
                          success: function(res){
                                          $('#value').replaceWith(
                                          "<div id='value'><h6>" + res + "</h6></div>"
                                          );
                                      }
                          });
                  });


来源:https://stackoverflow.com/questions/4075450/show-data-at-div-after-use-focus-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!