Ajit Teli
2012-Aug-02 06:19 UTC
Onchange of one select_tag, it should update another select_tag which is having same selected value
Dear all, I have two columns in a table: 1. vehicles, 2. drivers. The table lists all the vehicles in vehicles column and drivers column will have select_tag dropdown to select a driver. For ex, following drivers are set to vehicles. vehicle1 -> driver1 vehicle2 -> select vehicle3 -> driver2 Here, when change driver for vehicle1 from driver1 to driver2 using drop-down list, I am updating the database table for both vehicle1 and vehicle3. But I need to update the driver to ''select'' for vehicle3. May I know how can I do this? Thanks, Ajit -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Aug-02 08:01 UTC
Re: Onchange of one select_tag, it should update another select_tag which is having same selected value
On 2 August 2012 07:19, Ajit Teli <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear all, > > I have two columns in a table: 1. vehicles, 2. drivers. > The table lists all the vehicles in vehicles column and drivers column > will have select_tag dropdown to select a driver. > > For ex, following drivers are set to vehicles. > > vehicle1 -> driver1 > vehicle2 -> select > vehicle3 -> driver2 > > Here, when change driver for vehicle1 from driver1 to driver2 using > drop-down list, I am updating the database table for both vehicle1 and > vehicle3. But I need to update the driver to ''select'' for vehicle3. May > I know how can I do this?What have you tried and what about it did not work? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Ajit Teli
2012-Aug-02 09:18 UTC
Re: Onchange of one select_tag, it should update another select_tag which is having same selected va
This is the code which I am using for select_tag.
<td align=''center''>
<% driver = d.driver ? d.driver : nil %>
<% selected = d.driver.nil? ? 0 : d.driver.id %>
<% current_drivers = @current_user.sorted_drivers.collect{ |u| [u.name,
u.id]} %>
<%= select_tag(:id, options_for_select( [["Select", 0]] +
current_drivers, selected ),
:onchange => ( "if (confirm(''Would you like to assign driver
'' +
this.options[this.selectedIndex].text + '' to device #{
d.s_uf_name}?''))
{" + remote_function(
:url=> { :controller => :limos, :action => :updatedrivervehicle,
:device_id => d.id, :predriver_id => d.driver}, :method => :post,
:with => with_params( :driver_id
=>''this.options[this.selectedIndex].value'' )) + ";
sdvs[#{ i }] =
this.selectedIndex; } else { this.selectedIndex = sdvs[#{ i }]; }")) %>
<% old_index= driver ? (current_drivers.index( [driver.name,driver.id]
))+1 : 0 %>
<%= javascript_tag "sdvs[#{ i }] = #{old_index} " %>
</td>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.