使用JS(prototype& Rails 3)更改hidden_​​field_tag的值 [英] Change value of hidden_field_tag with JS (prototype & Rails 3)

查看:89
本文介绍了使用JS(prototype& Rails 3)更改hidden_​​field_tag的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3并使用Prototype.那就是说我只是在问一个JS问题.

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.

但是,我还有另一个页面,其中显示了很多教师.与其像上面的代码中那样自己放置讲师ID,不如根据按下哪个提交按钮来更改隐藏字段的值.

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.

即,一种形式,多个提交按钮.表单将提交,一切顺利,用户将可以继续并单击另一个提交按钮,将其数据发送给另一位讲师.为此,我想使用javascript来更改单击时隐藏字段的值.

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!" %>

这是表单的一个简单的讲师版本,本质上我在说的是在其中放置一个提交按钮和讲师ID的循环.

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%>

所以我的问题是-更改隐藏字段标记的js是什么? 附加问题-这对我来说很合理,可能是垃圾,如果有更明智的解决方案,请告诉我!

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!

谢谢!

推荐答案

document.getElementById('theId').value = "what ever you want";

就像彼此之间input

这篇关于使用JS(prototype&amp; Rails 3)更改hidden_​​field_tag的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆