?
Solved

is there a jquery calendar of days of month where some days can be disabled

Posted on 2013-05-26
13
Medium Priority
?
167 Views
Last Modified: 2013-06-19
do not want user to click on unavailable days

is this possible

want to use something simple such as jquery datepicker
not complex

<input type="text" id="datepicker" class="datepicker hasDatepicker" name="membership_enddate" value="1969-12-31">
0
Comment
Question by:rgb192
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39198477
Not so clear.
0
 

Author Comment

by:rgb192
ID: 39198517
http://jsfiddle.net/HePNg/

$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , [ "2012-05-13","2012-05-14","2012-05-15","2012-05-17" ] ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }

Open in new window



$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , 
<?php
foreach ($dates as $date){
$date_list.= ' " '.$date.' ",'
//remove last comma
}

 ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }

Open in new window




so would this php work for your jquery
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 83

Expert Comment

by:leakim971
ID: 39199003
test yourself your own code, step by step
create a new php file, put your code alone inside, open the page in your browser, if you don't see what you're looking for, do a right click and choose view source
if you don't see what you're looking for the answer is no

At first look, you miss the brackets []
AND
you don't echo/print something
0
 

Author Comment

by:rgb192
ID: 39199315
datepicker has calender with no missing dates
date-required has no calendar
  <?php
    $dates=array (
    "2013-05-13","2013-05-14","2013-05-15","2013-05-17"
    );
  ?>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , [
<?php
foreach ($dates as $date){
$date_list.= '"'.$date.'",';
}
$date_list=rtrim($date_list, ',');
echo $date_list;
?>
]
 ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window



view source
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , [
"2013-05-13","2013-05-14","2013-05-15","2013-05-17"]
 ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 39201003
You did not create a calendar for datepicker
date_required work fine
http://jsfiddle.net/WVuLK/1/
0
 

Author Comment

by:rgb192
ID: 39202904
I notice that your example works but my php does not work
id date required: no calendar
id: datepicker: calendar but no dates missing

php
  <?php
    $dates=array (
    "2013-05-13","2013-05-14","2013-05-15","2013-05-17"
    );
  ?>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', firstDay: 1});      
      
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , [
<?php
foreach ($dates as $date){
$date_list.= '"'.$date.'",';
}
$date_list=rtrim($date_list, ',');
echo $date_list;
?>
]
 ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window


html
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

$('#date_required').datepicker({ 
              dateFormat: 'yy-mm-dd',
            firstDay: 1,      
    beforeShowDay: disableDate, 
      }); 
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', firstDay: 1});      
      
                  });


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , [
"2013-05-13","2013-05-14","2013-05-15","2013-05-17"]
 ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 39206116
>> but my php does not work
Copy and paste the code below and give it a try:
  <?php
    $dates=array (
    "2013-05-13","2013-05-14","2013-05-15","2013-05-17"
    );
	
	$dates='["'.implode('","').']';
  ?>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

	$('#date_required').datepicker({ 
              	dateFormat: 'yy-mm-dd',
            	firstDay: 1,      
				beforeShowDay: disableDate
      }); 

	$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', firstDay: 1});      
      
});


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , <?php echo $dates; ?> ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window

0
 

Author Comment

by:rgb192
ID: 39206319
Warning: implode() [function.implode]: Argument must be an array in C:\Users\Acer\Documents\NuSphere PhpED\Projects\hielo-datepicker-disable.php on line 6
0
 
LVL 82

Expert Comment

by:hielo
ID: 39207855
My apologies.  This:
$dates='["'.implode('","').']';

should have been:
$dates='["' . implode('","' ,$dates) . ']';
0
 

Author Comment

by:rgb192
ID: 39241599
  <?php
    $dates=array (
    "2013-05-13","2013-05-14","2013-05-15","2013-05-17"
    );
  
  $dates='["' . implode('","' ,$dates) . ']';
  ?>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<script type="text/javascript">
$(document).ready(function() {

  $('#date_required').datepicker({ 
                dateFormat: 'yy-mm-dd',
              firstDay: 1,      
        beforeShowDay: disableDate
      }); 

  $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', firstDay: 1});      
      
});


function disableDate(d) {
     return [($.inArray( d.getFullYear() + "-" + d2(d.getMonth()*1+1) + "-" + d2(d.getDate()) , <?php echo $dates; ?> ) < 0), ''];
}

function d2(n) {return (n>9)?n:"0"+n; }
</script>


<p>id: date_required: <input type="text" id="date_required" value="2013-05-12" /></p>
<p>id: datepicker: <input type="text" id="datepicker" value="2013-05-12" /></p>

Open in new window



no dates are disabled
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 39253094
line 6 is missing a double quotation mark right before the closing bracket.  It should be:
 $dates='["' . implode('","' ,$dates) . '"]';
0
 

Author Closing Comment

by:rgb192
ID: 39261189
thank you for blocking out unwanted dates
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question