views:

95

answers:

2

I need to populate the first box with the items from a db table. Users would choose from the first box, and either drag value(items) to the second for selection, or would select items, and then click a button to move them over to the 2nd box. After that I need to update the db with the selected values/items.

A: 

First step: Code a loop to populate the first box with the db values.

Next: Drag&Drop is going to get more complicated than you want if you're just starting out. Depending on the setup, you might be able to do a pretty simple onclick() event to update the second box and not require a button, but to match the behavior you said, point the button to a javascript function which looks at the value set for the first box and then adds them to the second box. There are probably more elegant ways to do this, but just using .innerhtml should work.

Finally: Code the processing page to use update the db based on the values of the second box.

I don't get what the second box is accomplishing in this. Is it like a preview (here's what I'll add to the db if you click submit) type of thing?

JGB146
I ended up doing a nested form using AJAX and a partial render:<h5>Select a user to add:</h5><% form_tag :action =>"create" do %><%= select_tag "ntuserid", options_for_select(@names, []),{:size => 1, :include_blank => :true} %><%= observe_field "ntuserid", :update => "details", :with => 'ntuserid', :url => { :controller => "users", :action => "get_user_details"} %><div id="details"></div>This is working great. Thanks for the help!
Tonya Cash
A: 

You are correct. The second box is a "preview". I would like to hit submit, and then add the items to a db.

Tonya