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

  • SEARCH
  • Home
  • 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 7447427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:35:58+00:00 2026-05-29T12:35:58+00:00

I’m using Ruby on Rails to populate a database from a form that has

  • 0

I’m using Ruby on Rails to populate a database from a form that has multiple input text or select fields. I’m using AJAX so that every time the user makes a change in any input field, all input fields values are automatically taken into account and some other result fields get refreshed.

Everything works fine with the following script for the 1st 2 input fields, but I’m planning to have 50+ input fields if not more, and I wonder if there is a smarter way to implement my script without explicitly defining a separate function for each field.

I’d appreciate any idea how to scale my script without repeating the same thing 50+ times?

This is my js

<script type="text/JavaScript">
$(function(){
    $('.input_1_class').bind('change', function(){
        $.ajax({
            url: "<%= update_fields_projects_url %>",
            data: {
                input_1: $('.input_1_class').val(),
                input_2: $('.input_2_class').val(),
            }
        });
    });
    $('.input_2_class').bind('change', function(){
        $.ajax({
            url: "<%= update_fields_projects_url %>",
            data: {
                input_1: $('.input_1_class').val(),
                input_2: $('.input_2_class').val(),
            }
        });
    });
});
</script>

and this is my Ruby form (simplified)

<%= form_for(@project, :html => {:name => "ProjectInfo"}) do |f|
  field_set_tag "Customer Information" do %>

    <div class="field">
      <%= f.label :"Input 1" %>
      <%= f.text_field :Input_1, {:class=>"input_1_class"} %>
      <%= f.label :"Input 2" %>
      <%= f.text_field :Input_2, {:class=>"input_2_class"} %>
      <%= f.label :"Output 1" %>
      <%= f.text_field :Output_1, {:id=>"output_1_id"} %>
    </div>
  <% end %>
<% end %>
  • 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. Editorial Team
    Editorial Team
    2026-05-29T12:35:58+00:00Added an answer on May 29, 2026 at 12:35 pm

    You can specify multiple selectors, and have the same event bound to all of them:

    $('.input_1_class, .input_2_class').click(function ()
    {
        alert('Bound to both inputs');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.