Home>
I want to get the contents of an input text with

when submitting a completely different form, enter it into a hidden field (a field invisible to the user), and send it.

If i google
document.forms. (id of referenced form). (id of referenced text box) .value
There are a lot of acquisitions like, but I didn't come out about writing, so I asked this question.

It can be a useful site, so please let me know.
Thank you.

<input type = "text" name = "namae" size = "40" maxlength = "20">
<% = form_with (model: @user_info, url: "/ xxx/yyy", local: true, html: {id: "comment_form", onklick: "send ()"}) do | f |%>
   <% = f.hidden_field: txt_contents,: value =>''%>
   <% = f.submit 'Send', id: 'xxx_btn'%>
<% end%>

<script>
function send () {
   --- I want to put the contents of the above input into the hidden field ----
}
</script>
  • Answer # 1

    document.getElementById (''). value = 'hoge';


    Is this not good?

Related articles