简体   繁体   English

如何从另一个输入文本字段 Javascript 中输入的值将值设置为输入隐藏字段

[英]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.

相关问题 将Javascript输入隐藏字段的值设置为在另一个输入文本字段中输入的值的值 - Set the value of a Javascript input hidden field to that of a value entered in another input text field 如何通过 JavaScript 设置输入隐藏字段的值? - How to set the value of a input hidden field through JavaScript? 在javascript的输入数字类型字段中输入值时如何显示输入文本字段? - How to show a input text field when a value is entered in input number type field in javascript? 如何显示从输入字段的输入值到另一个输入字段的查询结果 - How To Display Query Result From Entered Value of Input Field To Another Input Field Javascript将输入文本字段设置为值不起作用 - Javascript set input text field to value not working 用另一个输入字段值更新隐藏的输入字段值? - Update hidden input field value with another input field value? 如何基于另一个输入字段设置一个输入字段的值? - How to set value of one input field based on another input field? 输入到输入字段的文本被复制到另一个输入字段的值的状态 - 为什么? - Text entered into an input-field is being duplicated to the state of another input field's value - why? 从另一个输入字段值(动态输入字段)在输入字段中设置值Sql查询结果 - Set Value Sql Query Result in Input Field From Another Input Field Value (Dynamic Input Field) 如何触发Span元素填充在“输入”字段(Javascript)中输入的值 - How to trigger the Span element to populate with the value entered in Input field (Javascript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM