How do I insert an input's value into a separate form?

Posted by ryan on Stack Overflow See other posts from Stack Overflow or by ryan
Published on 2010-04-19T19:44:52Z Indexed on 2010/05/23 6:00 UTC
Read the original article Hit count: 329

I'm making a tool for my university that allows students to create a list of classes by doing the following:

  1. Searching by course title for their course via an autocomplete input field.

  2. Adding that course to a separate form that upon being submitted creates a course list.

I am trying to link the autocomplete and the course list form with an 'add to course list' button that inserts a hidden input field into the course list form which can subsequently be submitted by a 'create course list' button.

My question is this: How do I take the value of the autocomplete input and insert it into the course list form without using AJAX?

So far I have something like the following:

<%= text_field_with_auto_complete :course, :title, :size => 40 %>
<%= link_to_function "Add to Course List" do |page|
    page.insert_html :top, :course_list, hidden_field(:courses, :course, 
    {:value => "$('course_title').value"}) %>

<% form_for(@course_list) do |f|%>
    <div id="course_list">Insert selected courses here.</div>
<% end %>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ruby-on-rails