ruby on rails - JQuery ajax form submit resets select value and does not persist it -


i've got select field using filter results on table. when pick option select fires ajax , updates table... however, resets select once table has updated. if use text box filter don't run issue.

form:

<%= form_tag items_path, method: :get, class: "navbar-form search-form", remote: true %>   <%= select_tag :search, options_from_collection_for_select(model.all, "id", "id"), include_blank: true, class: "form-control", id: "filter-key" %> <% end %> 

js/jquery

$(document).ready(function(){    $(document).on("change", "#filter-key", function(){     var form = $('.search-form');     $.get(form.action, form.serialize(), null, 'script');     return false;   });  }); 

something in script that's being returned must resetting select value. save value , put in ajax code.

var self = $(this); var oldvalue = self.val(); $.getscript(form.attr('action'), form.serialize(), function() {     self.val(oldvalue); }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo