admin管理员组文章数量:1328030
I'm riding Rails 3 and using Prototype. That said I'm only really asking a JS question..
I have a form, it's pretty simple. In the form I have a hidden field tag:
<%= hidden_field_tag(:instructor_id, @instructor.id) %>
That's all fine and well when I am submitting the form to one particular instructor.
I have another page, however, which displays a lot of instructors. Rather than put the instructor id there myself, as in the code above, I'd like to change the value of the hidden field depending on which submit button is pressed.
Ie, one form, several submit buttons. The form will submit and all being well the user will be able to go on and hit another submit button, sending their data through to another instructor. To achieve this I want to use javascript to alter the value of my hidden field on click.
<%form_for :call_back_request, :remote => true, :url => {:action => "call_back_request"} do |c| %>
<%= hidden_field_tag(:instructor_id, @instructor.id) %>
<%= hidden_field_tag(:pr_ok, true) %>
<%= c.text_field :first_name, :class => "profilesmstext" %>
<%= c.text_field :last_name, :class => "profilesmstext"%><br />
<%= c.text_field :postcode, :class => "profilesmstexta"%>
<%= c.text_field :telephone_number, :class => "profilesmstext" %>
<%= c.submit, :value="Go!" %>
That's the simple one instructor version of the form, essentially what I'm talking about doing is putting a loop of submit buttons and instructor ids in there.
So I'll have a loop (pseudo code..)
@instructors each do |i|
<%=c.submit, :value => "go!", :onclick => "javascript to change hidden field value"%>
<script / js>
<function doChicagoShuffleOnId etc >
</script>
<%end%>
So My question is - what is the js to change that hidden field tag? Additional question - This makes perfect sense to me, may be rubbish, if there is a more sensible solution please let me know!
Thanks!
I'm riding Rails 3 and using Prototype. That said I'm only really asking a JS question..
I have a form, it's pretty simple. In the form I have a hidden field tag:
<%= hidden_field_tag(:instructor_id, @instructor.id) %>
That's all fine and well when I am submitting the form to one particular instructor.
I have another page, however, which displays a lot of instructors. Rather than put the instructor id there myself, as in the code above, I'd like to change the value of the hidden field depending on which submit button is pressed.
Ie, one form, several submit buttons. The form will submit and all being well the user will be able to go on and hit another submit button, sending their data through to another instructor. To achieve this I want to use javascript to alter the value of my hidden field on click.
<%form_for :call_back_request, :remote => true, :url => {:action => "call_back_request"} do |c| %>
<%= hidden_field_tag(:instructor_id, @instructor.id) %>
<%= hidden_field_tag(:pr_ok, true) %>
<%= c.text_field :first_name, :class => "profilesmstext" %>
<%= c.text_field :last_name, :class => "profilesmstext"%><br />
<%= c.text_field :postcode, :class => "profilesmstexta"%>
<%= c.text_field :telephone_number, :class => "profilesmstext" %>
<%= c.submit, :value="Go!" %>
That's the simple one instructor version of the form, essentially what I'm talking about doing is putting a loop of submit buttons and instructor ids in there.
So I'll have a loop (pseudo code..)
@instructors each do |i|
<%=c.submit, :value => "go!", :onclick => "javascript to change hidden field value"%>
<script / js>
<function doChicagoShuffleOnId etc >
</script>
<%end%>
So My question is - what is the js to change that hidden field tag? Additional question - This makes perfect sense to me, may be rubbish, if there is a more sensible solution please let me know!
Thanks!
Share Improve this question asked Apr 1, 2012 at 15:16 LpLrichLpLrich 2,5332 gold badges21 silver badges31 bronze badges1 Answer
Reset to default 7document.getElementById('theId').value = "what ever you want";
Just like with every other input
本文标签: javascriptChange value of hiddenfieldtag with JS (prototype amp Rails 3)Stack Overflow
版权声明:本文标题:javascript - Change value of hidden_field_tag with JS (prototype & Rails 3) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742239837a2438755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论