Updating a select in a form


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?