Hiding input when radio checked not working

Hiding input when radio checked not working

Hi,

I have this page:

  1. <script type="text/javascript">
  2. modalExtra = '';
  3. maxModalHt = '';
  4. $(document).ready(function() {
  5. $('select, input[type="checkbox"], input[type="radio"], input[type="file"]').not('.productOptionPickListSwatch input, .productOptionViewRectangle input').uniform();
  6. modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 60;
  7.  
  8.  
  9. maxModalHt =  $(window).height() - modalExtra;
  10. $('#ModalContent').css('max-height', maxModalHt);
  11. });
  12. $('#giftwrapping_all').change(function() {
  13. modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
  14. maxModalHt =  $(window).height() - modalExtra;
  15. $('#ModalContent').css('max-height', maxModalHt);
  16. });

  17. $(window).load(function(){
  18.     modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
  19. maxModalHt =  $(window).height() - modalExtra;
  20. $('#ModalContent').css('max-height', maxModalHt);
  21. });

  22. $(window).bind( 'orientationchange', function(e){
  23.     modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
  24. maxModalHt =  $(window).height() - modalExtra;
  25. $('#ModalContent').css('max-height', maxModalHt);
  26. });

  27. $(window).load(function() {
  28. $('#datepicker').datepicker();
  29. });               
  30. </script>
  31. <div id="ModalTitle">Choose Your Options</div> 
  32. <form id="CartEditProductFieldsForm" method="post" action="cart.php" onsubmit="return Cart.saveItemCustomizations();"  enctype="multipart/form-data">
  33. <input type="hidden" name="action" value="EditProductFieldsInCart" />
  34. <div id="ModalContent" style="overflow: auto;">
  35. <!--- Standard Shipping --->
  36. <label for="Standard">
  37. <input id="Standard" type="radio" value="86" checked="checked" onclick="javascript:ShipDate();" />
  38. Standard Shipping<br />
  39. <p><small>Earliest Date of Delivery: 
  40. <span id="delivery-date"></span></small></p>
  41. </label><br />
  42. <!--- Delivery Date Field --->
  43. <div id="cartDatepickerDiv" class="ml25">       
  44. <label id="datepickerLabel" for="datepicker" class="rl-m">Desired Delivery Date: </label>
  45. <input class="input-small" id="datepicker" type="text" placeholder="ex. 01/01/2013" readonly />               
  46. <hr>
  47. </div>  
  48. <!--- 2 Day Express --->
  49. <label for="2DayExpress">
  50. <input id="2DayExpress" type="radio" value="89" onclick="javascript:ShipDate();" />
  51. Delivery by&nbsp;<span id="datepicker2"></span>
  52. <p class="rl-m"><small><span class="name">2 Day Express Shipping. Additional $27.00.</span></small></p>                                                
  53. </label>
  54. <br />
  55. <!--- 3 Day Express --->
  56. <label for="3DayExpress">
  57. <input id="3DayExpress" type="radio" value="90" onclick="javascript:ShipDate();" />
  58. Delivery by&nbsp;<span id="datepicker3"></span>
  59. <p class="rl-m"><small><span class="name">3 Day Express Shipping. Additional $17.00.</span></small></p>            
  60. </label>
  61. <br />
  62. <!--- Gift Message --->
  63. <h8>Gift Message</h8>                    
  64. <label for="giftMsg">
  65. <small>Please type your desired message (optional)</small>:<br />
  66. </label>                       
  67. <textarea id="giftMsg" value=""></textarea>                   
  68. <br />        
  69. </div>
  70. <div id="ModalButtonRow">
  71. <a href="#" onclick="$.modal.close();" class="Button btn-small FloatLeft">Cancel</a>
  72. <input class="Button btn-small FloatRight" class="Submit" type="submit" value="Save" />
  73. </div>
  74. <!--- Datepicker Script --->
  75. <script>
  76. $(document).ready(function() {

  77. var natDays = [
  78. [1, 1, 'New Year'], //2014
  79. [1, 20, 'Martin Luther King'], //2014
  80. [2, 17, 'Washingtons Birthday'], //2014       
  81. [5, 26, 'Memorial Day'], //2014
  82. [7, 4, 'Independence Day'], //2014
  83. [9, 1, 'Labour Day'], //2014
  84. [10, 14, 'Columbus Day'], //2013
  85. [11, 11, 'Veterans Day'], //2013
  86. [11, 28, 'Thanksgiving Day'], //2013 
  87. [12, 25, 'Christmas'] //2013     
  88. ];

  89. // dateMin is the minimum delivery date
  90. var dateMin = new Date();
  91. dateMin.setDate(dateMin.getDate() + (dateMin.getHours() >= 14 ? 1 : 0));

  92. function AddBusinessDays(curdate, weekDaysToAdd) {
  93. var offset = (weekDaysToAdd > 0 ? +1 : -1);
  94. weekDaysToAdd = Math.abs(weekDaysToAdd);
  95. var date = new Date(curdate.getTime());
  96. while (weekDaysToAdd > 0) {
  97. date.setDate(date.getDate() + offset);
  98. //check if current day is business day
  99. if (noWeekendsOrHolidays(date)) {
  100. weekDaysToAdd--;
  101. }
  102. }
  103. return date;
  104. }

  105. function noWeekendsOrHolidays(date) {
  106. var noWeekend = $.datepicker.noWeekends(date);
  107. return (noWeekend[0] ? nationalDays(date) : noWeekend);
  108. }

  109. function nationalDays(date) {
  110. for (i = 0; i < natDays.length; i++) {
  111. if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
  112. return [false, natDays[i][2] + '_day'];
  113. }
  114. }
  115. return [true, ''];
  116. }

  117. function setDeliveryDate(date) {
  118. $('#delivery-date').text($.datepicker.formatDate('DD, MM d, yy', date));
  119. $('#datepicker3').text($.datepicker.formatDate('DD, MM d, yy',
  120. AddBusinessDays(date, -1)));
  121. $('#datepicker2').text($.datepicker.formatDate('DD, MM d, yy',
  122. AddBusinessDays(date, -2)));
  123. }

  124. setDeliveryDate(AddBusinessDays(dateMin, 4));

  125. $.datepicker.setDefaults({
  126. beforeShowDay: noWeekendsOrHolidays,
  127. showOn: 'both',
  128. firstDay: 0,
  129. dateFormat: 'mm/dd/yy',
  130. changeFirstDay: false,
  131. showButtonPanel: true
  132. });
  133. // use datepicker to choose a different delivery date    
  134. $('#datepicker').datepicker({
  135. minDate: AddBusinessDays(dateMin, 4),
  136. onSelect: function(datestring) {
  137. setDeliveryDate($(this).datepicker('getDate'));
  138. }
  139. });
  140. });
  141. //formats dates in modal
  142. var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  143. var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  144. var d = new Date();
  145. var curr_day = d.getDay();
  146. var curr_date = d.getDate();
  147. var sup = "";
  148. if (curr_date == 1 || curr_date == 21 || curr_date ==31)
  149. {
  150. sup = "st";
  151. }
  152. else if (curr_date == 2 || curr_date == 22)
  153. {
  154. sup = "nd";
  155. }
  156. else if (curr_date == 3 || curr_date == 23)
  157. {
  158. sup = "rd";
  159. }
  160. else
  161. {
  162. sup = "th";
  163. }
  164. var curr_month = d.getMonth();
  165. var curr_year = d.getFullYear();    

  166.     /* collect all the inputs, radio, textarea and select */
  167.     var originalInputs=$('.productAttributeList :input');
  168.     
  169.     var newElArray=[
  170.     /* selector , index of original input*/
  171.     ['#Standard',1],     
  172.     ['#2DayExpress',2],
  173.     ['#3DayExpress',3],
  174.     ['#giftMsg',4], 
  175.     ['#datepicker',5],
  176.     ['#age_verification',7]
  177.     ]
  178.     
  179.     /* index of original input to match to modal fields */
  180.     $.each(  newElArray,function(i,arr){
  181.     var newName= getInputName( arr[1])
  182.     $(arr[0]).attr('name', newName);     
  183.     })

  184.     function getInputName( index){
  185.     return originalInputs.eq(index).attr('name');
  186.     }
  187. </script>
  188. </form>​
  189. <script>  
  190. //hides unnecessary fields on modal
  191.     $(".productOptionViewRadio span.name:contains('(None)')").parents('li').hide(); 
  192.     $('.productAttributeConfigurableEntryCheckbox').hide();
  193.     $("label span.name:contains('Date')").parents('.productAttributeRow').hide();  
  194. //hide date field when standard shipping is checked
  195.     $("input[type="radio"]").click(function() {
  196.     if ($(this).is(":checked")) $("#cartDatepickerDiv").hide();
  197.         else $("#cartDatepickerDiv").show();
  198.     });
  199. });
  200. </script>


I'm new so I'm sure there's a million issues with it...but what I'm posting about is the last function which isn't working at all. It's supposed to hide #cartDatepickerDiv when the radio id="Standard" is checked but it's doing nothing.

Any help or advice is very much appreciated.
Susan