Jquery Datepicker with XML file

Posted by matt on Stack Overflow See other posts from Stack Overflow or by matt
Published on 2010-04-15T17:21:37Z Indexed on 2010/04/15 17:23 UTC
Read the original article Hit count: 968

an extension of my last question, http://stackoverflow.com/questions/2562986/getdate-with-jquery-datepicker ,

I am trying to use the jquery datepicker to load specific info from xml file dependent on the date selected by the user. Similar code but i am trying to load and parse an xml file to read contents of the file for the particular date.

In a perfect world the user would tap a date and below the datepicker html output would give the user specific times for the selected date instead of my last project of an image.

my probelm is nothing is loading, so my question is what am i doing wrong?

my code is as follows

<!DOCTYPE html>

    <link type="text/css" href="css/ui-darkness/jquery-ui-1.8.custom.css" rel="stylesheet" />   
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script>
    <script type="text/javascript">
        $(function(){
            // Datepicker
            $('#datepicker').datepicker({
                dateFormat: 'yy-mm-dd',
                inline: true,
                minDate: new Date(2010, 1 - 1, 1),
                maxDate:new Date(2010, 12 - 1, 31),
                altField: '#datepicker_value',
                onSelect: function(){
                    var day1 = $("#datepicker").datepicker('getDate').getDate();                 
                    var month1 = $("#datepicker").datepicker('getDate').getMonth() + 1;             
                    var year1 = $("#datepicker").datepicker('getDate').getFullYear();
                    var fullDate = year1 + "" + month1 + "" + day1;
                    //var str_output ="<img src=\"http://69.89.20.27/images/a" + fullDate +".png\" width=\"100%\"/>";
                    //"<h1>"+fullDate+"</h1>";
                    //"<img src=\"http://69.*.*.*/images/a" + fullDate +".png\"/>";
                    //$('#page_output').html(str_output);
                        var doc = loadXMLDoc('date.xml'); // loading the XML file
                        var el = doc.getElementsByTagName('_'+date); // retrieving the elements corrsponding to a date, eg: _20100103
                        var page_output = document.getElementById('page_output');   

                        if(el.length >= 1)
                        {
                            // matched XML data found for the specified date    
                            var dt = el[0].getElementsByTagName('date');
                            var great_times = el[0].getElementsByTagName('great_times');
                            var good_times = el[0].getElementsByTagName('good_times');      
                            var str_output = "<h1><center>" + dt[0].childNodes[0].nodeValue + "</center></h1><br/><br>";
                            str_output += "<b>Excellent Times:</b><br> " + great_times[0].childNodes[0].nodeValue + "<br/><br>";
                            str_output += "<b>Good Times:</b><br> " + good_times[0].childNodes[0].nodeValue + "<br/><br>";
                            $('#page_output').html(str_output);// writing the results to the div element (page_out)
                        }
                        else
                        {
                            alert("Sorry","Action not allowed on this page");
                            page_output.innerHTML = ''; // No XML data found for the selected date
                            reloadmainwDate();      
                            return false;
                        }   
                        return true;    
                }
            });             
            //hover states on the static widgets
            $('#dialog_link, ul#icons li').hover(
                function() { $(this).addClass('ui-state-hover'); }, 
                function() { $(this).removeClass('ui-state-hover'); }
            );          
        });
        //var img_date = .datepicker('getDate');
            //var day1 = $("#datepicker").datepicker('getDate').getDate();               
            //var month1 = $("#datepicker").datepicker('getDate').getMonth() + 1;               
            //var year1 = $("#datepicker").datepicker('getDate').getFullYear();
            //var fullDate = year1 + "-" + month1 + "-" + day1;
            //var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
            //var str_output = "<h1><center><p>"+ date + "</p></center></h1>";
            //$('#page_output')[0].innerHTML = str_output;



    // writing the results to the div element (page_out)
    </script>
    <script>

function loadXMLDoc(dname) { var xmlDoc;

// IE 5 and IE 6
if(typeof ActiveXObject != 'undefined') 
{   
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    xmlDoc.load(dname);
    return xmlDoc;
}
else if (window.XMLHttpRequest) // firefox
{
    xmlDoc=new window.XMLHttpRequest();
    xmlDoc.open("GET",dname,false);
    xmlDoc.send("");
    return xmlDoc.responseXML;
}
alert("Error loading document");
return null;

}

    <!-- Datepicker -->

    <div id="datepicker"></div>

    <!-- Highlight / Error -->

    <div id="page_output"></div>


</body>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-datepicker