Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 33843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:59:07+00:00 2026-05-10T13:59:07+00:00

In Ruby on Rails, I’m attempting to update the innerHTML of a div tag

  • 0

In Ruby on Rails, I’m attempting to update the innerHTML of a div tag using the form_remote_tag helper. This update happens whenever an associated select tag receives an onchange event. The problem is, <select onchange='this.form.submit();'>; doesn’t work. Nor does document.forms[0].submit(). The only way to get the onsubmit code generated in the form_remote_tag to execute is to create a hidden submit button, and invoke the click method on the button from the select tag. Here’s a working ERb partial example.

<% form_remote_tag :url => product_path, :update => 'content', :method => 'get' do -%>   <% content_tag :div, :id => 'content' do -%>     <%= select_tag :update, options_for_select([['foo', 1], ['bar', 2]]), :onchange => 'this.form.commit.click' %>     <%= submit_tag 'submit_button', :style => 'display: none' %>   <% end %> <% end %> 

What I want to do is something like this, but it doesn’t work.

<% form_remote_tag :url => product_path, :update => 'content', :method => 'get' do -%>   <% content_tag :div, :id => 'content' do -%>     # the following line does not work     <%= select_tag :update, options_for_select([['foo', 1], ['bar', 2]]), :onchange => 'this.form.onsubmit()' %>   <% end %> <% end %> 

So, is there any way to remove the invisible submit button for this use case?

There seems to be some confusion. So, let me explain. The basic problem is that submit() doesn’t call the onsubmit() code rendered into the form.

The actual HTML form that Rails renders from this ERb looks like this:

<form action='/products/1' method='post' onsubmit='new Ajax.Updater('content', '/products/1', {asynchronous:true, evalScripts:true, method:'get', parameters:Form.serialize(this)}); return false;'>   <div style='margin:0;padding:0'>     <input name='authenticity_token' type='hidden' value='4eacf78eb87e9262a0b631a8a6e417e9a5957cab' />   </div>   <div id='content'>     <select id='update' name='update' onchange='this.form.commit.click'>       <option value='1'>foo</option>       <option value='2'>bar</option>     </select>     <input name='commit' style='display: none' type='submit' value='submit_button' />   </div> </form> 

I want to axe the invisible submit button, but using a straight form.submit appears to not work. So, I need some way to call the form’s onsubmit event code.

Update: Orion Edwards solution would work if there wasn’t a return(false); generated by Rails. I’m not sure which is worse though, sending a phantom click to an invisible submit button or calling eval on the getAttribute('onsubmit') call after removing the return call with a javascript string replacement!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:59:07+00:00Added an answer on May 10, 2026 at 1:59 pm

    If you didn’t actually want to submit the form, but just invoke whatever code happened to be in the onsubmit, you could possibly do this: (untested)

    var code = document.getElementById('formId').getAttribute('onsubmit'); eval(code); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried parsedatetime? May 11, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer I'm guessing you also need to add the Accordion to… May 11, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer I found a solution / hack after all (in C#):… May 11, 2026 at 4:50 pm

Related Questions

In Ruby on Rails, I'm attempting to update the innerHTML of a div tag
In my Ruby on Rails app, I have a User table and a Foo
In Ruby on Rails Development (or MVC in general), what quick rule should I
I recently wrote mailing list software in Ruby On Rails. I would like to
I'm in the process of maintaining a Ruby on Rails app and am looking

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.