1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Select Multiple Days

Discussion in 'JavaScript' started by Jim K, Nov 10, 2019.

  1. #1
    This script is for a datepicker. Can someone help modify this script so that it disables Tuesday, Thursday & Sunday. It currently works for Sunday only and can't figure out how to make it work for multiple days.
    
    <script type="text/javascript">
    function noSundays(date) {
       var weekday=new Array(7);
       weekday[0]="Sunday";
       weekday[1]="Monday";
       weekday[2]="Tuesday";
       weekday[3]="Wednesday";
       weekday[4]="Thursday";
       weekday[5]="Friday";
       weekday[6]="Saturday";
       //console.log(weekday[date.getDay()]);
       if(weekday[date.getDay()] == 'Sunday') {
         return [false, '', 'Not available Sundays'];
      }else if(weekday[date.getDay()] == 'Sunday') {
      return [false, '', 'Not available Sundays'];
      }
    
       return [true];
    }
    jQuery(window).load(function(){
       jQuery('.hasDatepicker').datepicker('option', 'beforeShowDay', noSundays);
    });
    </script>
    
    Code (markup):

     
    Solved! View solution.
    Last edited: Nov 10, 2019
    Jim K, Nov 10, 2019 IP
  2. #2
    That's a pretty clear chunk of code and a good learning opportunity for you

    <script type="text/javascript">
    function daysClosed(date) {
    var weekday=new Array(7);
    weekday[0]="Sunday";
    weekday[1]="Monday";
    weekday[2]="Tuesday";
    weekday[3]="Wednesday";
    weekday[4]="Thursday";
    weekday[5]="Friday";
    weekday[6]="Saturday";
    //console.log(weekday[date.getDay()]);
    if(weekday[date.getDay()] == 'Sunday') {
    return [false, '', 'Not available Sundays'];
    }else if(weekday[date.getDay()] == 'Tuesday') {
    return [false, '', 'Not available Tuesdays'];
    }
    else if(weekday[date.getDay()] == 'Thursday') {
    return [false, '', 'Not available Thursdays'];
    }
    
    return [true];
    }
    jQuery(window).load(function(){
    jQuery('.hasDatepicker').datepicker('option', 'beforeShowDay', daysClosed);
    });
    </script>
    Code (javascript):
     
    sarahk, Nov 10, 2019 IP
  3. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    818
    Best Answers:
    7
    Trophy Points:
    320
    #3
    You were on the right track. If you had not checked for Sunday TWICE, you might have found the problem without @sarahk's help.



     
    mmerlinn, Nov 10, 2019 IP
  4. Jim K

    Jim K Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Got it. Thank you.
     
    Jim K, Nov 11, 2019 IP