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.

    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题