开发者

How to update database on select dropdown list using Ajax?

Looking for a way where I can update a database whwnever I select anything in dropdpwn. So if I select A from dropdown that value should save in database using A开发者_运维技巧jax.

Thanks,


I have assumed that you have drop drop boxes in a form.

Firstly for all the drop down give the same class name and onchange of the options i have submitted the form.Put this code in your file and check.You can pass the options in drop_down_options and also params if any.

<%= form_for(@entry, :url => entries_path, :html => {:id => 'drop_down_form', :method => 'GET'}) do |f| %>
  <%= f.select :first_d_down ,options_for_select(drop_down_options, params),{:include_blank => 'first value'},{:class => 'drop_down',:style =>"width:200px;"}%>
<%end%>

   $('.drop_down').change(function(){
     $('#drop_down_form').submit();
   return false;
   })

Include this in script tag

Hope it helps ,do reply if any further queries

Thanx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜