Solved

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

Posted on 2013-05-26
13
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is initialize not a function? 8 52
disable and enable textboxes in dataTable 7 32
boostsrap 1 13
Make Float not to Wrap 15 37
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)

730 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