Javascript question: How do I duplicate user input

2019-06-09 09:37发布

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?

4条回答
劳资没心,怎么记你
2楼-- · 2019-06-09 09:53
$("#id_of_hidden_input").val($("#id_of_text_input").val());
查看更多
该账号已被封号
3楼-- · 2019-06-09 09:59

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

查看更多
淡お忘
4楼-- · 2019-06-09 10:06

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())
查看更多
再贱就再见
5楼-- · 2019-06-09 10:12

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.

查看更多
登录 后发表回答