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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:14:45+00:00 2026-06-10T07:14:45+00:00

I am trying to access the value of an element in a different form.

  • 0

I am trying to access the value of an element in a different form. More specifically I have two forms, one normal html form which submits the information, and an ajax form that updates a field in the database. I want the ajax form to take the value of an element in the normal form, but I have no idea how to accomplish that. Here is my current setup:

Message View

<%= form_for @message do |f| %>
    <%= f.text_field :to %>
    <%= f.text_area :body %>
    <%= f.submit "Send Message" %>
<% end %>
<%= form_for :save, :url => save_message_path(), :remote => :true do |f| %>
    <%= f.submit "Save" %>
<% end %>

Message Controller

def save
    account.message = params[:body]
end

But the :body param is in the other form so it sets account.message to nil because the ajax form did not have a body parameter. I would like it so the ajax form can submit the value of the body element.

  • 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-06-10T07:14:47+00:00Added an answer on June 10, 2026 at 7:14 am

    Since the form is edited on the client side, you’ll have to write this functionality in javascript.

    It is relatively straightforward to copy the value of the message body into a hidden field and submit the Ajax form. This would be most easily accomplished by adding an id your ajax form as follows:

    <%= form_for :save, :url => save_messages_path(), :remote => true, :id => 'ajaxform' %>
      <%= hidden_field_tag 'hidden_message' %>
    

    Then in javascript you could do the following:

    $(document).ready(function(){
      $("#ajaxform").submit(function() {
        $("#hidden_message").val($("#message_body").val());
        return true;
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to access a Servlet from a button on HTML page //Html Page FORM
I am trying to access an element which is inside of a frame but
I am trying to access the first element of a TreeMap, I have the
I am trying to access the text value of a xml element. I am
I'm trying to access a value in a nested array in Autoit, but I'm
I'm trying to access the value() of a UIAStaticText (a UILabel in the objective
I'm trying to access an associative array's key and value from within the same
I am trying to use for..in loop to access the description key/value within 'Event'
I'm trying to autocomplete a textbox. I'm retrieving values from Access Database. Just one
I'm trying to access the number in the below element, but I'm having trouble

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.