In my Ruby-on-Rails application, a user can fill in their zipcode and house number. When they click submit, the two other fields will be filled with the correct street name and city name.
I want that when I click the submit button, Ajax retrieves the correct streetname and city from my database and fills it in the correct fields so it will only refresh this part of the page, not the entire web page.
<%= form_tag(zipcodes_path, :method => 'get', action: "/", :id => "zipcodes_search", remote: false) do %>
<%= text_field_tag 'zipcode', params[:zipcode], placeholder: "Postcode", data: {zipcode: true}, :class => "must_be_filled"%>
<%= text_field_tag 'house_number', params[:house_number], placeholder: "Huisnummer", :class => "must_be_filled" %>
<%= submit_tag "Search", :name => nil, :id => "submit_button" %>
<div id="zipcode_results">
<%= text_field_tag 'street_name', @street_name, :id => "street_name", placeholder: "Straatnaam", readonly: true %>
<%= text_field_tag 'city', @city, :id => "city", placeholder: "Woonplaats", readonly: true %>
</div>
I can retrieve the streetname and city using gon if it is needed.
I think I need to use the .load() function, but I just started using ajax so I am a bit lost.
Let me know if you need more code or wish to know anything else.