title: Jquery UI datepicker to allow dynamic specific days of week only
body: <p>I would like to disable certain days in a jQuery UI datepicker based on the days entered in one of the input boxes by the user.</p>
  
  <p>If i enter <strong>MWF</strong> it should only allow me to only select the dates which falls on either "<strong>M</strong>"onday , "<strong>W</strong>"ednesday ot "<strong>F</strong>"riday</p>
  
  <p>I am able to dynamically construct the return value sting which needs to be set in the return statement.</p>
  
  <pre><code> for (var j=0; j &lt; arr.length; j++)
        mystr = mystr + "day != " + arr[j] + " &amp;&amp; ";
  
        mystr = mystr.substring(0, mystr.length - 3);
  </code></pre>
  
  <p>This gives me the following text in mystr variable: </p>
  
  <pre><code>day != 3 &amp;&amp; day != 4 &amp;&amp; day != 6 
  </code></pre>
  
  <p>which needs to passed on to the return statement like :</p>
  
  <pre><code>​$("#datepicker").datepicker({
      beforeShowDay: function(date) {
          var day = date.getDay();
          return [(mystr)];
      }
  })​​​​​;​
  </code></pre>
  
  <p>This is not working....</p>
  
  <p>I am able to disable the days i want if i explicitly set it in return statement. But i need to dynamically restrict days selection in the datepicker based on days entered in the text box. I can get the days dynamically and also have the dynamic return statement ready. Its not working. </p>
  
  <p>FULL CODE :</p>
  
  <pre><code>            var batchdays = ['M', 'T', 'W', 'H', 'F', 'S'];
              var batchcode= "MWF";
              var batchdaysarray = batchcode.replace(/\d+/g, '').split('');
              var arr = [];
              var arrayLength = batchdaysarray.length;
  
              for (var i = 0; i &lt; arrayLength; i++) {
                      if ($.inArray(batchdaysarray[i], batchdays) != -1) {
                          arr.push($.inArray(batchdaysarray[i], batchdays)+1);
                      }
              }
  
              var mystr = '';
  
              for (var j=0; j &lt; arr.length; j++)
                  mystr = mystr + "day != " + arr[j] + " &amp;&amp; ";
  
              mystr = mystr.substring(0, mystr.length - 3);
  
              alert(mystr);
              console.log(mystr);
  
              $('#actual_start_dt').datepicker({
                  dateFormat: 'dd-mm-yy',
                  prevText: '&lt;i class="fa fa-chevron-left"&gt;&lt;/i&gt;',
                  nextText: '&lt;i class="fa fa-chevron-right"&gt;&lt;/i&gt;',
                  beforeShowDay: function(date) {
                      var day = date.getDay();
                      return [(mystr)];
                  }
              });
  </code></pre>
  
  <p>Please help</p>