Hiding input when radio checked not working
Hi,
I have this page:
- <script type="text/javascript">
- modalExtra = '';
- maxModalHt = '';
- $(document).ready(function() {
- $('select, input[type="checkbox"], input[type="radio"], input[type="file"]').not('.productOptionPickListSwatch input, .productOptionViewRectangle input').uniform();
- modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 60;
-
-
- maxModalHt = $(window).height() - modalExtra;
- $('#ModalContent').css('max-height', maxModalHt);
- });
- $('#giftwrapping_all').change(function() {
- modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
- maxModalHt = $(window).height() - modalExtra;
- $('#ModalContent').css('max-height', maxModalHt);
- });
- $(window).load(function(){
- modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
- maxModalHt = $(window).height() - modalExtra;
- $('#ModalContent').css('max-height', maxModalHt);
- });
- $(window).bind( 'orientationchange', function(e){
- modalExtra = $('#ModalTitle').outerHeight(true) + $('#ModalButtonRow').outerHeight(true) + 30;
- maxModalHt = $(window).height() - modalExtra;
- $('#ModalContent').css('max-height', maxModalHt);
- });
- $(window).load(function() {
- $('#datepicker').datepicker();
- });
- </script>
- <div id="ModalTitle">Choose Your Options</div>
- <form id="CartEditProductFieldsForm" method="post" action="cart.php" onsubmit="return Cart.saveItemCustomizations();" enctype="multipart/form-data">
- <input type="hidden" name="action" value="EditProductFieldsInCart" />
- <div id="ModalContent" style="overflow: auto;">
-
- <!--- Standard Shipping --->
- <label for="Standard">
- <input id="Standard" type="radio" value="86" checked="checked" onclick="javascript:ShipDate();" />
- Standard Shipping<br />
- <p><small>Earliest Date of Delivery:
- <span id="delivery-date"></span></small></p>
- </label><br />
-
- <!--- Delivery Date Field --->
- <div id="cartDatepickerDiv" class="ml25">
- <label id="datepickerLabel" for="datepicker" class="rl-m">Desired Delivery Date: </label>
- <input class="input-small" id="datepicker" type="text" placeholder="ex. 01/01/2013" readonly />
- <hr>
- </div>
-
- <!--- 2 Day Express --->
- <label for="2DayExpress">
- <input id="2DayExpress" type="radio" value="89" onclick="javascript:ShipDate();" />
- Delivery by <span id="datepicker2"></span>
- <p class="rl-m"><small><span class="name">2 Day Express Shipping. Additional $27.00.</span></small></p>
- </label>
- <br />
-
- <!--- 3 Day Express --->
- <label for="3DayExpress">
- <input id="3DayExpress" type="radio" value="90" onclick="javascript:ShipDate();" />
- Delivery by <span id="datepicker3"></span>
- <p class="rl-m"><small><span class="name">3 Day Express Shipping. Additional $17.00.</span></small></p>
- </label>
- <br />
- <!--- Gift Message --->
- <h8>Gift Message</h8>
- <label for="giftMsg">
- <small>Please type your desired message (optional)</small>:<br />
- </label>
- <textarea id="giftMsg" value=""></textarea>
- <br />
- </div>
- <div id="ModalButtonRow">
- <a href="#" onclick="$.modal.close();" class="Button btn-small FloatLeft">Cancel</a>
- <input class="Button btn-small FloatRight" class="Submit" type="submit" value="Save" />
- </div>
- <!--- Datepicker Script --->
- <script>
- $(document).ready(function() {
- var natDays = [
- [1, 1, 'New Year'], //2014
- [1, 20, 'Martin Luther King'], //2014
- [2, 17, 'Washingtons Birthday'], //2014
- [5, 26, 'Memorial Day'], //2014
- [7, 4, 'Independence Day'], //2014
- [9, 1, 'Labour Day'], //2014
- [10, 14, 'Columbus Day'], //2013
- [11, 11, 'Veterans Day'], //2013
- [11, 28, 'Thanksgiving Day'], //2013
- [12, 25, 'Christmas'] //2013
- ];
- // dateMin is the minimum delivery date
- var dateMin = new Date();
- dateMin.setDate(dateMin.getDate() + (dateMin.getHours() >= 14 ? 1 : 0));
- function AddBusinessDays(curdate, weekDaysToAdd) {
- var offset = (weekDaysToAdd > 0 ? +1 : -1);
- weekDaysToAdd = Math.abs(weekDaysToAdd);
- var date = new Date(curdate.getTime());
- while (weekDaysToAdd > 0) {
- date.setDate(date.getDate() + offset);
- //check if current day is business day
- if (noWeekendsOrHolidays(date)) {
- weekDaysToAdd--;
- }
- }
- return date;
- }
- function noWeekendsOrHolidays(date) {
- var noWeekend = $.datepicker.noWeekends(date);
- return (noWeekend[0] ? nationalDays(date) : noWeekend);
- }
- function nationalDays(date) {
- for (i = 0; i < natDays.length; i++) {
- if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
- return [false, natDays[i][2] + '_day'];
- }
- }
- return [true, ''];
- }
- function setDeliveryDate(date) {
- $('#delivery-date').text($.datepicker.formatDate('DD, MM d, yy', date));
- $('#datepicker3').text($.datepicker.formatDate('DD, MM d, yy',
- AddBusinessDays(date, -1)));
- $('#datepicker2').text($.datepicker.formatDate('DD, MM d, yy',
- AddBusinessDays(date, -2)));
- }
- setDeliveryDate(AddBusinessDays(dateMin, 4));
- $.datepicker.setDefaults({
- beforeShowDay: noWeekendsOrHolidays,
- showOn: 'both',
- firstDay: 0,
- dateFormat: 'mm/dd/yy',
- changeFirstDay: false,
- showButtonPanel: true
- });
- // use datepicker to choose a different delivery date
- $('#datepicker').datepicker({
- minDate: AddBusinessDays(dateMin, 4),
- onSelect: function(datestring) {
- setDeliveryDate($(this).datepicker('getDate'));
- }
- });
- });
- //formats dates in modal
- var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
-
- var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
-
- var d = new Date();
- var curr_day = d.getDay();
- var curr_date = d.getDate();
- var sup = "";
- if (curr_date == 1 || curr_date == 21 || curr_date ==31)
- {
- sup = "st";
- }
- else if (curr_date == 2 || curr_date == 22)
- {
- sup = "nd";
- }
- else if (curr_date == 3 || curr_date == 23)
- {
- sup = "rd";
- }
- else
- {
- sup = "th";
- }
- var curr_month = d.getMonth();
- var curr_year = d.getFullYear();
-
- /* collect all the inputs, radio, textarea and select */
- var originalInputs=$('.productAttributeList :input');
-
- var newElArray=[
- /* selector , index of original input*/
- ['#Standard',1],
- ['#2DayExpress',2],
- ['#3DayExpress',3],
- ['#giftMsg',4],
- ['#datepicker',5],
- ['#age_verification',7]
- ]
-
- /* index of original input to match to modal fields */
- $.each( newElArray,function(i,arr){
- var newName= getInputName( arr[1])
- $(arr[0]).attr('name', newName);
- })
- function getInputName( index){
- return originalInputs.eq(index).attr('name');
- }
- </script>
- </form>
- <script>
- //hides unnecessary fields on modal
- $(".productOptionViewRadio span.name:contains('(None)')").parents('li').hide();
- $('.productAttributeConfigurableEntryCheckbox').hide();
- $("label span.name:contains('Date')").parents('.productAttributeRow').hide();
-
- //hide date field when standard shipping is checked
- $("input[type="radio"]").click(function() {
- if ($(this).is(":checked")) $("#cartDatepickerDiv").hide();
- else $("#cartDatepickerDiv").show();
- });
- });
- </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