简体   繁体   中英

Why are the radio buttons resetting when clicking on this jquery datepicker

here is the jquery for the datepicker:

$.fn.dcalendarpicker = function(opts){
    return $(this).each(function(){
        var that = $(this);
        var cal = $('<table class="calendar"></table>'), hovered = false, selectedDate = false;
        that.wrap($('<div class="datepicker" style="display:inline-block;position:relative;"></div>'));
        cal.css({
            position:'absolute',
            left:0, display:'none',
            'box-shadow':'0 4px 6px 1px rgba(0, 0, 0, 0.14)',
            width:'230px',
        }).appendTo(that.parent());
        if(opts){
            opts.mode = 'datepicker';
            cal.dcalendar(opts);
        }
        else
            cal.dcalendar({mode: 'datepicker'});
        cal.hover(function(){
            hovered = true;
        }, function(){
            hovered = false;
        }).on('click', function(){
            // SCRIPT MOD - skip radio buttons
            if(!selectedDate)
                that.focus();
            else {
                selectedDate = false;
                $(this).hide();
            }
        }).on('selectdate', function(e){
            that.val(e.date).trigger('onchange');
            that.trigger($.Event('dateselected',{date: e.date, elem: that}));
            selectedDate = true;
        });
        that.on('keydown', function(e){ if(e.which) return false; })
            .on('focus', function(){
                $('.datepicker').find('.calendar').not(cal).hide();
                cal.show();
            })
            .on('blur', function(){ if(!hovered) cal.hide(); });
    });
}

Here is the php/html:

echo "<fieldset>";
        echo "<h5>Select Your Delivery Date:  </h5>";
        echo "<label class=\"error_label\">".$error_juice_delivery."</label>";
        echo "<label>Select weekly or monthly deliveries:  <label><br>";
        $type_1 = $type_2 = '';
        if($delivery_type === '1') $type_1 = 'checked';
        else $type_2 = 'checked';
        echo "Weekly <input type=\"radio\" name=\"delivery_date_type\" value=\"1\" $type_1 /><br>";
        echo "Monthly <input type=\"radio\" name=\"delivery_date_type\" value=\"2\" $type_2 /><br>";
        echo "<br><label>Type in delivery start date(has to be atleast one week from today)</label>";
        echo "(mm/dd/yyyy) <input id =\"calendar-demo\" type=\"text\" name=\"delivery_start_date\" value=\"".$delivery_date."\"/><br>";
    echo "</fieldset>";

for some reason every time i click the date input field in the fieldset above, and select a date from the jquery datepicker dropdown, the weekly/monthly radio button selection is reset, and i have no idea why...

I figured it out...I had the label tag unclosed:

echo "<label>Select weekly or monthly deliveries:  <label><br>";

should be:

echo "<label>Select weekly or monthly deliveries:  </label><br>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM