Solved

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

Posted on 2013-05-26
13
160 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 82

Expert Comment

by:leakim971
ID: 39198476
0
 
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 82

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 82

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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Questions about this React unit test 4 64
jQuery Syntax 2 52
MVC5 - Two different JQuery libraries are loading???? 2 22
Create an automated page index 9 18
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

821 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