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 6827079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:13:26+00:00 2026-05-26T22:13:26+00:00

Hello people I’m trying to figured this out, but I still can’t do it.

  • 0

Hello people

I’m trying to figured this out, but I still can’t do it.

I have a rails 3 app, I’m working with invoices and payments. In the form for payments I have a collection_select where I display all the invoices number (extracted from a postgres database), and what I’m trying to do is when i select an invoice autopopulate others text_fields (provider, address, etc.) without reloading the page, in the same form.

I know I should use ajax, js, jquery, but I’m a beginner in these languages, so i don’t know how or where to start

hope you can help me… thanks

  • 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-26T22:13:26+00:00Added an answer on May 26, 2026 at 10:13 pm

    What you are going to want to do is route an ajax call to a controller, which will respond with json containing the information. you will then use jquery to populate the different fields.

    In your routes:

    get "invoice/:id/get_json", :controller=>"invoice", :action=>"get_json"
    

    In your invoice_controller:

    def get_json
      invoice = Invoice.find(params[:invoice_id])
      render :text => invoice.to_json
    end
    

    In your invoice model (if the default to_json method is not sufficent):

    def to_json
      json = "{"
      json += "id:'#{self.id}'"
      json += ",date_created:'#{self.date}'"
      ...      //add other data  you want to have here later
      json += "}"
    end
    

    In your javascript file,

    $("#invoice_selecter").change(function(){  //calls this function when the selected value changes
      $.get("/invoice/"+$(this).val()+"/get_json",function(data, status, xhr){  //does ajax call to the invoice route we set up above
        data = eval(data);  //turn the response text into a javascript object
        $("#field_1").val(data.date_created);  //sets the value of the fields to the data returned
        ...
      });
    });
    

    You are probably going to run into a few issues, i would highly recommend downloading and installing fire bug if you are not on google chrome.. and if you are, make sure you are using the development tools. I believe you can open them up by right clicking and hitting inspect element. Through this, you should be able to monitor the ajax request, and whether or not it succeeded and things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello to all you people out there I have been trying to download the
Hello people of stackoverflow. I have a problem. I'm trying to set up my
Hello people I have made a custom title bar for my app. I would
Let's say I have this sample: page = <html><body><h1 class='foo'></h1><p class='foo'>hello people<a href='http://'>hello world</a></p></body></html>
Hello for all people... Sorry for my english, but speak spanish... In this week,
Hello fellow Computer People! I could do this myself, but was just wondering if
Hello wonderful people of stackoverflow! I have a problem. I am working on an
Hello kind computing people, Okay this is super broad, but I thought I'd give
Hello people can someone help. I have designed a dialog in which I would
Hello Good People !! I have a web application (my first of this type)

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.