I want to create a form for making a reservation for borrowed items. A reservation consists of pick up time, return time and items the reserver wants to borrow and their amounts. For example, I might want to reserve three plates, three knives and three forks for the rest of the week.
In the form, I want to do an AJAX validation that checks whether there is enough items available. Next to each item I have a text box with which the reserver inputs the item amount. After the input, I want to do an onchange call that checks if the amount of items is available for the given dates. Thus, I need to pass the remote function called in the onchange following parameters: item id, item amount (value of the current textfield) and pick up time and return time which are both given in datetime_select fields above. This is my code:
<% with = "'amount='+value+'&item=#{item.id.to_s}&pick_up_time=#{@reservation.pick_up_time.to_s}&return_time=#{@reservation.return_time.to_s}'" %>
<%= text_field_tag "reservation[#{prefix}reserved_items][#{item.id}]", get_amount_value(item, @reservation), :size => 3, :onchange => "#{remote_function(:url => { :controller => :items, :action => :availability }, :with => with, :update => availability_url) }" %>
Obviously, this does not work since @reservation.return_time and @reservation.pick_up_time are not yet set because the form is not yet sent. My question is: how do I get those values? I believe that it should be done via a javascript call, but I didn't manage to insert a javascript call in the "with" variable or at least didn't get it to work. Does anybody have any idea on what I should do?