Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <p class="form-row form-row-wide">
  2. <label for="select_price_option">Price option<span class="required"> *</span></label>
  3. <select name="select_price_option" id="select_price_option" />
  4. <option disabled selected value> Please select one</option>
  5. <option>Total fee</option>
  6. <option>Starting fee</option>
  7. <option>I need more information</option>
  8. </select>
  9. </p>
  10.  
  11. <p class="form-row form-row-wide" id="price_input_div">
  12. <label for="quote_price_input">Enter your price</label>
  13. <input type="text" name="quote_price_input" id="quote_price_input" class="input-text"/>
  14. </p>
  15.  
  16. <p class="form-row form-row-wide">
  17. <label for="message_to_customer">Enter your message<span class="required"> *</span></label>
  18. <textarea name="message_to_customer" id="message_to_customer" minlength="30" class="input-text"></textarea>
  19. </p>
  20.  
  21. // Save custom checkout fields to session storage
  22. (function ($) {
  23. // Run on page load
  24. window.onload = function() {
  25. var quote_price_input = sessionStorage.getItem("quote_price_input");
  26. var message_to_customer = sessionStorage.getItem("message_to_customer");
  27. var select_price_option = sessionStorage.getItem("select_price_option");
  28.  
  29. if(quote_price_input !== null) {
  30. document.getElementById('quote_price_input').value = quote_price_input;
  31. } else
  32. document.getElementById('quote_price_input').value = "";
  33.  
  34. if(select_price_option !== null) {
  35. var sel = document.getElementById('select_price_option');
  36. var opts = sel.options;
  37. for (var opt, j = 0; opt = opts[j]; j++) {
  38. console.log(opt.innerHTML);
  39. if (opt.innerHTML == select_price_option) {
  40. sel.selectedIndex = j;
  41. break;
  42. }
  43. }
  44. }
  45.  
  46. if(message_to_customer !== null) {
  47. document.getElementById('message_to_customer').innerHTML = message_to_customer;
  48. } else
  49. document.getElementById('message_to_customer').innerHTML = "";
  50. };
  51.  
  52. // Before refreshing the page, save the form data to sessionStorage
  53. window.onbeforeunload = function() {
  54. var quote_price_input = document.getElementById('quote_price_input');
  55. var message_to_customer = document.getElementById('message_to_customer');
  56. var select_price_option = document.getElementById('select_price_option');
  57.  
  58. if(quote_price_input !== null) {
  59. sessionStorage.setItem('quote_price_input', $('#quote_price_input').val());
  60. }
  61.  
  62. if(select_price_option !== null) {
  63. sessionStorage.setItem('select_price_option', $('#select_price_option').val());
  64. }
  65.  
  66. if(message_to_customer !== null) {
  67. sessionStorage.setItem('message_to_customer', $('#message_to_customer').val());
  68. }
  69. };
  70. })(jQuery);
  71.  
  72. (function ($) {
  73. $("#select_price_option").change(function() {
  74. if ($(this).val() == "I need more information") {
  75. $('#price_input_div').hide();
  76. } else {
  77. $('#price_input_div').show();
  78. }
  79. });
  80. $("#select_price_option").trigger("change");
  81. })(jQuery);
  82.  
  83. // Conditionally show price
  84. (function ($) {
  85. window.onload = function() {
  86. $("#select_price_option").change(function() {
  87. if ($(this).val() == "I need more info to give a price") {
  88. $('#price_input_div').hide();
  89. } else {
  90. $('#price_input_div').show();
  91. }
  92. });
  93. $("#select_price_option").trigger("change");
  94. }})(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement