Chris Hulbert
2005-Dec-21 02:48 UTC
How to make a drop-down automatically submit an AJAX form
Hi, 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" onchange="this.form.submit();"> <%= options_from_collection_for_select @departments, "id", "department_name" %> </select> <%= submit_tag "Open for Data Entry" %> <%= end_form_tag %> <div id="div_id_dataentry_bottom_ajax"> </div> -- Cheers, thanks all -- Posted via http://www.ruby-forum.com/.
Chris Hulbert
2005-Dec-21 05:00 UTC
Re: How to make a drop-down automatically submit an AJAX for
Anyone? -- Posted via http://www.ruby-forum.com/.
Raghuraman Suraj
2005-Dec-21 06:55 UTC
Re: How to make a drop-down automatically submit an AJAX form
Use onchange="this.form.onsubmit();" rather than submit straight. On Wed, 2005-12-21 at 03:48 +0100, Chris Hulbert wrote:> Hi, > 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" > onchange="this.form.submit();"> > <%= options_from_collection_for_select @departments, "id", > "department_name" %> > </select> > > <%= submit_tag "Open for Data Entry" %> > > <%= end_form_tag %> > > <div id="div_id_dataentry_bottom_ajax"> > </div> > -- > > > Cheers, thanks all >