Access hiddenfield


When I do view source of the page  I am having two forms as shown

//comes from different partial
form_tag action=“show” id=“show_form” do

//comes from different partial
form_tag delete_path id=“delete_form” do

100.times do|i|
<%=checkbox_tag :user_id , :value => user_ids[i]%>


In the delete_form when I select checkboxes and click on submit button I
will delete the selected user ids.
The same form I am using for sending emails to selected users when
clicking on Send button.
Trough jQuery when click on Send Button I am changing the form
var form = $(‘delete_form’)
form.setAttribute(“action”, “/users/send_email”)
var hidden_fields = $(“input[name= _method”])
//If hidden_fields[1].val(“post”) is not done then the _method value
will be “delete” and delete action is called through rails routes

Currently the above code works perfect. But later if the third form is
added above show_form then the above logic fails.
How should I access _method element of delete_form.

Funny that it works at all. But of course if you have a list of all
inputs where the attribute name has the value ‘_method’ (the meaning of
$(“input[name=_method]”) and access them by index the index changes when
you add another form above (hidden_fields[1] becomes hidden_fields[2]
and so on).

In jQuery different to Prototype you don’t say $(‘delete_form’) but
$(’#delete_form’)… Your javascript should rather look like this:

$(’#delete_form’).attr(“action”, “/users/send_email”);