Forum: Ruby on Rails How to make a drop-down automatically submit an AJAX 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.
Chris H. (Guest)
on 2005-12-21 04:48
I know that to make a dropdown box automatically submit when you change
the value, you do this:
<select ..... onchange="this.form.submit();">
BUT i've got an ajax form, and if i do the above trick, it simply
reloads the ajax partial into the whole screen, rather than into the div
where it is meant to go.
I've already got it all working so that if you click on the submit
button, all is fine, but i'd like to know how to make it automatic.

My RHTML code looks a bit like this:

<%= form_remote_tag :update => "div_id_dataentry_bottom_ajax", :url => {
:action => "dataentry_bottom_edit" } %>

<select id="department_id" name="department_id"
<%= options_from_collection_for_select @departments, "id",
"department_name" %>

<%= submit_tag "Open for Data Entry" %>

<%= end_form_tag %>

<div id="div_id_dataentry_bottom_ajax">

Cheers, thanks all
Chris H. (Guest)
on 2005-12-21 07:00
Raghuraman Suraj (Guest)
on 2005-12-21 08:56
(Received via mailing list)
Use onchange="this.form.onsubmit();" rather than submit straight.
Chris H. (Guest)
on 2005-12-22 00:02
Raghuraman Suraj wrote:
> Use onchange="this.form.onsubmit();" rather than submit straight.

This topic is locked and can not be replied to.