[英]how to set the value to a input hidden field from value entered in another input text field Javascript
I want to get this form name and put in form name hidden我想获取此表单名称并将表单名称隐藏
<input placeholder="Nome" class="form-control" type="text"
name="morning[name]"
id="morning_name">
hidden field隐藏字段
<input placeholder="Nome" hide_label="true" required="required"
type="hidden"
name="morning[foots_attributes][0][name]"
id="morning_foots_attributes_0_name">
my bootstrap_form我的 bootstrap_form
<%= bootstrap_form_with(model: @morning, url: morning_path, local: true) do |form| %>
<%= form.text_field :name, placeholder: "Nome", hide_label: true%>
<%= form.fields_for :foots do |foot| %>
<%= foot.hidden_field :name, placeholder: "Nome", hide_label: true, required: true %>
<% end %>
<%= form.submit "Registrar horário", class:"btn btn-primary", data: { disable_with:
'Registrando....' } %>
<% end %>
<%= javascript_pack_tag 'custom' %>
You can use the jQuery .change()
to accomplish this.您可以使用 jQuery
.change()
来完成此操作。
$("#morning_name").change(function(){
$("#morning_foots_attributes_0_name").val(this.value);
});
https://api.jquery.com/change/ https://api.jquery.com/change/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.