jQuery根据选择下拉列表显示其他字段值

时间:2016-09-12 10:56:46

标签: jquery ruby-on-rails-4

我是RoR的新手,我有两个模型CustomerDetail和Invoice.Im动态填充customer_name,它是从customer_detail创建的。我必须根据customer_name显示customer_id,地址。

JS

这是我的Jquery文件

$("#customer_name").prepend('<option selected="" value="Add New">Add New</option>');
 $("#customer_name").prepend("<option value='Add New'></option>").val('aaaaaaaaaa');
 $("#customer_name").on('change', function() {
   alert($('#customer_name').val());
   if ($('#customer_name').val() == 'Add New'){
     window.location.href = "/customer_details/new";
   }
 $('#cust_id').val($(this).find("option:selected").attr("value"));

 });
  <button type="button" class="btn dropdown-toggle form-control selectpicker btn-default" data-toggle="dropdown" data-id="customer_name" title="nnnnnnnn"><span class="filter-option pull-left">nnnnnnnn</span>&nbsp;<span class="caret"></span></button>
  <input autofocus="autofocus" class="form-control" id="cust_id" type="text" name="invoice[customer_id]">
问题是我无法根据客户名称的选择获得客户ID。有人请帮助我。提前谢谢!!

0 个答案:

没有答案
相关问题