Guest User

Untitled

a guest
Jun 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <script type="text/javascript">
  2. order_id=0;
  3. $(function(){
  4. add_order_item();
  5. $("select[name='order[accommodation_type_id]']").change(function () {
  6.  
  7. accommodation_type_id = $("select[name='order[accommodation_type_id]'] option:selected").val();
  8.  
  9. $.getJSON("/differences",{accommodation_type_id:accommodation_type_id},get_differences);
  10. function get_differences(differences) {
  11. differences_options="";
  12. $.each(differences,function(i,val){
  13. differences_options+="<option value="+val.id+">"+val.name+"</option>";
  14. })
  15. $(".differences_selection").html(differences_options);
  16. price();
  17. }
  18.  
  19. }).trigger('change');
  20.  
  21. function price(){
  22. $("select[name^='order[order_items][difference_id][1]']").change(function () {
  23. //alert($("select[name^='order[order_items][difference_id]']").attr("name"));
  24. name=$(this).attr("name");
  25. difference_id = $("select[name='"+name+"'] option:selected").val();
  26.  
  27. $.getJSON("/differences/"+difference_id+"/get_price",{date_begin:'2008-04-01',date_end:'2008-05-12'},get_price_amount);
  28. function get_price_amount(price_amount) {
  29. $("#order_order_items_price_"+order_id+" >span").html("стоимость: "+price_amount+"грн.");
  30. $("#order_order_items_price_"+order_id+" >input").val(price_amount);
  31. }
  32.  
  33. }).trigger('change');
  34. }
  35. });
  36.  
  37.  
  38. function add_order_item(){
  39.  
  40. accommodation_type_id = $("select[name='order[accommodation_type_id]'] option:selected").val();
  41. $.getJSON("/differences",{accommodation_type_id:accommodation_type_id},get_differences);
  42. function get_differences(differences) {
  43. order_id++;
  44. differences_selection="";
  45. differences_selection+="<select name='order[order_items][difference_id]["+order_id+"]' class='differences_selection'>";
  46. $.each(differences,function(i,val){
  47. differences_selection+="<option value="+val.id+">"+val.name+"</option>";
  48. })
  49. differences_selection+="</select>";
  50. $(differences_selection).appendTo("#differences");
  51. price="<div id='order_order_items_price_"+order_id+"'><span></span><input type='hidden' name='order[order_items][price]["+order_id+"]' /></div>";
  52. $(price).appendTo("#differences");
  53. }
  54.  
  55. }
  56.  
  57. </script>
Add Comment
Please, Sign In to add comment