Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.63 KB | None | 0 0
  1. $("#select_state_rebate").change(function () {
  2. $('#select_utility_rebate')
  3. .find('option')
  4. .remove()
  5. .end()
  6. .append('<option>Choose Utility</option>');
  7. $('#select_style_rebate')
  8. .find('option')
  9. .remove()
  10. .end()
  11. .append('<option>Choose Rebate Style</option>');
  12. if ($("#select_state_rebate")[0].selectedIndex > 0) {
  13. var state_val = $("#select_state_rebate").val();
  14. $("#select_utility_rebate").prop("disabled", false);
  15. $.ajax({
  16. url: 'productajax.php',
  17. data: {
  18. state: state_val,
  19. action: "utility"
  20. },
  21. type: 'POST',
  22. dataType: 'JSON',
  23. success: function (output) {
  24. var results = output;
  25. for (var i in results) {
  26. $('#select_utility_rebate').append($("<option/>", {
  27. value: results[i].utility,
  28. text: results[i].utility
  29. }));
  30. }
  31. },
  32. error: function () {}
  33. });
  34. } else {
  35. $("#select_utility_rebate").prop("disabled", true);
  36. $("#select_style_rebate").prop("disabled", true);
  37. $("#rebate_submit").prop("disabled", true);
  38. }
  39. });
  40.  
  41. $("#select_utility_rebate").change(function () {
  42. $('#select_style_rebate')
  43. .find('option')
  44. .remove()
  45. .end()
  46. .append('<option>Choose Rebate Style</option>');
  47. if ($("#select_utility_rebate")[0].selectedIndex > 0) {
  48. var state_val = $("#select_state_rebate").val();
  49. var utility_val = $("#select_utility_rebate").val();
  50. $("#select_style_rebate").prop("disabled", false);
  51. $.ajax({
  52. url: 'productajax.php',
  53. data: {
  54. state: state_val,
  55. utility: utility_val,
  56. action: "type"
  57. },
  58. type: 'POST',
  59. dataType: 'JSON',
  60. success: function (output) {
  61. var results = output;
  62. for (var i in results) {
  63. $('#select_style_rebate').append($("<option/>", {
  64. value: results[i].rebate_style,
  65. text: results[i].rebate_style
  66. }));
  67. }
  68. $("#rebate_submit").prop("disabled", false);
  69. },
  70. error: function () {}
  71. });
  72. } else {
  73. $("#select_style_rebate").prop("disabled", true);
  74. $("#rebate_submit").prop("disabled", true);
  75. $('#select_style_rebate')
  76. .find('option')
  77. .remove()
  78. .end()
  79. .append('<option>Choose Rebate Style</option>');
  80. }
  81. });
  82.  
  83.  
  84.  
  85.  
  86.  
  87. $("#rebate_form").submit(function (event) {
  88. $('.result').remove();
  89. var state_val = $("#select_state_rebate").val();
  90. var utility_val = $("#select_utility_rebate").val();
  91. var style_val = $("#select_style_rebate").val();
  92. $.ajax({
  93. url: 'productajax.php',
  94. data: {
  95. state: state_val,
  96. utility: utility_val,
  97. style: style_val,
  98. action: "submit"
  99. },
  100. type: 'POST',
  101. dataType: 'JSON',
  102. success: function (output) {
  103. var rebates = output;
  104. console.log(rebates);
  105.  
  106. $.ajax({
  107. url: 'productajax.php',
  108. data: {
  109. action: "getproduct"
  110. },
  111. type: 'POST',
  112. dataType: 'JSON',
  113. success: function (output) {
  114. $("#result_table").show();
  115. var products = output;
  116. console.log(products);
  117. for (var i in products) {
  118. for (var j in rebates) {
  119. if (products[i].category == rebates[j].lamp) {
  120. if (rebates[j].wattage_high === null) {
  121. if (rebates[i].existing_wattage_high === null) {
  122. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>'+ products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td></td><td>' + rebates[j].existing_type + '</td></tr>');
  123. } else if (rebates[i].existing_wattage_low === null) {
  124. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>'+ products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  125. } else {
  126. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>'+products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_low + '-' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  127. }
  128.  
  129. } else if (rebates[j].wattage_low === null) {
  130. if (products[i].wattage == rebates[j].wattage_high) {
  131. if (rebates[i].existing_wattage_high === null) {
  132. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>' + products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td></td><td>' + rebates[j].existing_type + '</td></tr>');
  133. } else if (rebates[i].existing_wattage_low === null) {
  134. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>'+products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  135. } else {
  136. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>'+products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_low + '-' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  137. }
  138. }
  139. } else if (products[i].wattage <= rebates[j].wattage_high && products[i].wattage >= rebates[j].wattage_low) {
  140. if (rebates[i].existing_wattage_high === null) {
  141. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>' + products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td></td><td>' + rebates[j].existing_type + '</td></tr>');
  142. } else if (rebates[i].existing_wattage_low === null) {
  143. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>' + products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  144. } else {
  145. $('#result_table tr:last').after('<tr class=result><td>' + products[i].image + '</td><td>' + products[i].code + '</td><td>' + products[i].category + '</td><td>' + products[i].wattage + '</td><td>' + products[i].product_number + '</td><td>' + products[i].description + '</td><td>$' + rebates[j].rebate + '</td><td>' + rebates[j].existing_wattage_low + '-' + rebates[j].existing_wattage_high + '</td><td>' + rebates[j].existing_type + '</td></tr>');
  146. }
  147. }
  148. }
  149. }
  150. }
  151. },
  152. error: function () {
  153. console.log('error');
  154. }
  155. });
  156. },
  157. error: function () {
  158. console.log('error');
  159. }
  160. });
  161. event.preventDefault();
  162.  
  163. });
  164. $("input[type='reset']").on('click', function (event) {
  165. $("#select_style_rebate").prop("disabled", true);
  166. $("#select_utility_rebate").prop("disabled", true);
  167. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement