Forum: Ruby on Rails Updating a select in a form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and 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?

This topic is locked and can not be replied to.