Solved

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

Posted on 2013-05-26
13
157 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
Comment Utility
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Not so clear.
0
 

Author Comment

by:rgb192
Comment Utility
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
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
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
Comment Utility
You did not create a calendar for datepicker
date_required work fine
http://jsfiddle.net/WVuLK/1/
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:rgb192
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
My apologies.  This:
$dates='["'.implode('","').']';

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

Author Comment

by:rgb192
Comment Utility
  <?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
Comment Utility
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
Comment Utility
thank you for blocking out unwanted dates
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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 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)

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now