Forum: Ruby on Rails Updating a select in a form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joshua Gitlin (Guest)
on 2006-02-10 04:00
(Received via mailing list)
Hey everyone,

I have a form with two selects, a category and a sub category.
Obviously, the sub-category menu cannot be filled in until a category
is chosen and must change based on what category is chosen. Before I
was using AJAX on this form I had an onchange="this.form.submit()" on
the category select, and the controller knew to simply re-render the
view if params[:commit].length == 0.

Worked great.

When I switched to AJAX for this form I made the onchange for the
category menu "this.form.onsubmit()" to get the AJAXification. Now,
the effect I'm seeing is that if I choose a category, the DIV
refreshes, the sub-category menu is filled in properly, BUT the form
is acting as if the "Save" button was clicked, so I see the empty
fields highlighted in red with the error messages.

How can I test to see when the form is submitted if the submit button
was actually clicked? Why is the onsubmit() handler sending a value
for the submit button that wasn't clicked?

-Josh
This topic is locked and can not be replied to.