Solved

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

Posted on 2013-05-26
13
159 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)

911 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

18 Experts available now in Live!

Get 1:1 Help Now