Wednesday, April 13, 2016

Honus part 5: fixing the date picker

The past couple of days I made a few simple fixes to the site, such as changing the color of the selected game so it would be clear which game the highlights were for. A problem I had been thinking about was that the datepicker, which uses jQuery, wasn't getting set to the selected day and always defaulted to the current day. Part of the problem was that I had data in the php file that I needed to pass to the datepicker, which was controlled by a function in my javascript file.

The obvious solution was to move the javascript code into the php file, and then just echo in the wanted date. The code below does this, and the commented out line shows how it worked before in the script file. There was probably an easier way, but this works.

<?php
// This section sets the datepicker day to the selected day
echo '<script  type="text/javascript">
//  jQuery ready function. Specify a function to execute when the DOM is fully loaded. 
$(document).ready(
 // This is the function that will get executed after the DOM is fully loaded 
 function () {console.log("ready 0987520933");
$( "#datepicker" ).datepicker({
 changeMonth: true,//this option for allowing user to select month
 changeYear: true //this option for allowing user to select from year range
});
var today = new Date();console.log("08"+"/"+today.getDate()+"/"+today.getFullYear());
//$( "#datepicker" ).datepicker("setDate",(today.getMonth()+1)+"/"+today.getDate()+"/"+today.getFullYear());
$( "#datepicker" ).datepicker("setDate",' . $month . '+"/"+ ' . $day . '+"/"+' . $year . ');
 }
);
</script>';
?>

Unfortunately I've noticed that the website is getting slower to load. I don't have the skills right now to improve this, but I'll have to think about it in the future. The next thing I'm thinking about adding is a boxscore, or list of scoring plays. And the long-term goal is to give the site memory of what you visited and store a list of  highlights so it doesn't have to get the XML page from MLB every time.

No comments:

Post a Comment