How can I pass input from a text-type input element into a hidden input element in the same form on a site that has jquery installed?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Triggered when the text changes:
$("#text_id").change(function(){
$("#hidden_id").val($("#text_id").val())
});
Triggered when the form submits:
$("#form_id").submit(function(){
$("#hidden_id").val($("#text_id").val())
});
Check out other jQuery Events.
回答2:
If input_1
is the id of the input you want to populate, and input_2
the id you want to populate from, use:
$("#input_1").val($("#input_2").val())
回答3:
$("#id_of_hidden_input").val($("#id_of_text_input").val());
回答4:
Assuming that you have only one field of each type:
$('input[type=hidden]').val($('input[type=text]').val())
If you have more add IDs to selectors