douzhuan1432 2019-07-13 13:24
浏览 87

从组合选择中获取价值,并使用jQuery和Laravel将结果显示到文本字段

I'd like to display certain record from table according combo/drop selection in Laravel. I'm following instructions from this thread but still can not get it to work.

Here is my view code and my jQuery script:

a. combo box

<select type="text" class="form-control" name="cde_mesg" id="cmb_mesg" required>
  <option value="0" disabled="true" selected="true">
    -- PICK MESSAGE-- 
  </option>
  @foreach($message as $messages)
    <option value="{{ $messages->cde_mesg }}">
      {{ $messages->nme_customer }}
    </option>
  @endforeach
</select>

b. text field

<input type="text" name="ad1_contract" id="ad1_contract" class="form-control">

c. jquery script

<script type="text/javascript">
  $(document).ready(function(){
    $("#cmb_mesg").change(function(){
      var x =  $(this).val();
      $("#ad1_contract").val(x);
    });
  });
</script>
  • 写回答

1条回答 默认 最新

  • dsfhe34889789708 2019-07-13 15:37
    关注

    It doesn't make sense that this is not working as it is presented... unless there is some dynamic element changing after page load perhaps? If so, try changing your jQuery ready function to:

    $("#cmb_mesg").on('change', function(){
          var x =  $(this).val();
          $("#ad1_contract").val(x);
    });
    

    The benefits of doing the on (delegated) vs change (direct) are well explained in this answer, with further references to other good explanations. You can review further the .on("change", selector, handler) there, as well, to see if that makes a difference.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题