JS jQuery datepicker Help Needed

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
well im using this script right here:
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/

and I have a multiMonth(http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth3.html) plugin and multiple select enabled(http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiple.html).


I want to be able to on load have certain dates already selected and those dates come from a database.
I found two possible clues to help me out, but since I have not strictly learned JS yet, I can not made heads or tails.
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/renderCalendarBankHolidays.html
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDefaultToday.html

here's the code right now im using:
Code:
<script type="text/javascript" charset="utf-8">
   jQuery(function() {
      jQuery('#multimonth').datePickerMultiMonth({
         numMonths: 12,
         inline: true,
         selectMultiple: true,
         startDate: '01/09/2009', // DD/MM/YY
         month: 8, // 0=JAN  1=FEB ...
         year: 2009
      }).bind(
         'dpMonthChanged',
         function(event, displayedMonth, displayedYear) {
          //uncomment if you have firebug and want to confirm this works as expected...
          //console.log('dpMonthChanged', arguments);
      }).bind(
         'dateSelected',
         function(event, date, jQuerytd, status) {
         //uncomment if you have firebug and want to confirm this works as expected...
         //console.log('dateSelected', arguments);
      })[COLOR=Red].val(
         new Date().asString()).trigger('change');[/COLOR]
      jQuery('#getSelected').bind(
         'click',
         function(e) {
            alert(jQuery('#multimonth').dpmmGetSelected());
            return false;
      });
   });
   </script>


Code:
.val(new Date().asString()).trigger('change');
and this part is not being selected, I took it from the select todays date demo



and as a bonus, if anyone has any ideas to speed up the load, because right now the page takes forever to load, and I don't have anything to show any progress, so the end user might think the thing is broken.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
The datepicker you are using seems that it needs to much work. I know you already have it installed but I would highly suggest working with an easier script.

I have used this one in a few application I have developed and it works like a dream.

http://www.mattkruse.com/javascript/calendarpopup/index.html

He wants something that will show several months at once. I don't see where the one you suggest has that feature. He also wants several dates preselected, which is not a feature of that setup either.

And, to be blunt, the JQuery implementation looks much more professional that the one you suggest (that uses pop-up windows).
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
okay guys,
so I found out how to do it.

but now another problem arises.
I have a PHP script stuck into the JS code, im not sure if that is already the problem, but the PHP code draws dates out from the db.
Code:
<script type="text/javascript" charset="utf-8">
   jQuery(function() {
      jQuery('#multimonth').datePickerMultiMonth({
         numMonths: 12,
         inline: true,
         selectMultiple: true,
         startDate: '01/09/2009', // DD/MM/YY
         month: 8, // 0=JAN  1=FEB ...
         year: 2009
      }).bind(
         'dpMonthChanged',
         function(event, displayedMonth, displayedYear) {
          //uncomment if you have firebug and want to confirm this works as expected...
          //console.log('dpMonthChanged', arguments);
      }).bind(
         'dateSelected',
         function(event, date, jQuerytd, status) {
         //uncomment if you have firebug and want to confirm this works as expected...
         //console.log('dateSelected', arguments);
      });
      <?php
         $sql = "SELECT * FROM nextsession";
         $result = mysql_query($sql);
         while($row = mysql_fetch_array($result)) {
            echo "jQuery('#multimonth').dpmmSetSelected('".date("d/m/y", $row[1])."'); \n";
         }
      ?>
      //jQuery('#multimonth').dpmmSetSelected('22/09/2009');
      //jQuery('#multimonth').dpmmSetSelected('23/09/2009');
      jQuery('#getSelected').bind(
         'click',
         function(e) {
            alert(jQuery('#multimonth').dpmmGetSelected());
            return false;
      });
   });
   </script>

around the bottom you will see something like this
jQuery('#multimonth').dpmmSetSelected('22/09/2009');

the ones that are in comments are the ones that work
and the PHP ones doesn't
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
while($row = mysql_fetch_array($result)) {
  echo "jQuery('#multimonth').dpmmSetSelected('".date("d/m/y", $row[1])."'); \n";
 }

When you run the page, open the source and see what this code snippet actually prints. That will help you find problems. (Debugging 101A)

Also 'y' prints two digit for the year. 'Y' prints four.
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
thank you descalzo

I did check the script, but I over looked the year. I just changed it to 'Y' and it works now
 
Top