Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.getElementById().innerHTML problem

    Hi All,

    I have been searching high and low for a solution, or at least a reason, for a problem that I am having with document.getElementById().innerHTML.

    I am creating a "mini" calendar to use on my web page. What i am trying to do is make it so that when a user clicks the next month button, all of the DIVs that store the days of the month have the innerHTML cleard and then replaced with the days. And this works, but IE gives an error message and FireBug informs me that document.getElementById("d0") is null.

    The error is from this function:
    Code:
    function displayMini(dateX){
    	var x = new Date(dateX.getFullYear(),dateX.getMonth(),1);
    	var i = 0;
    	var d = 'd';
    	var ctr = 1;
    	for (i = 0; i < 42; i++){
    		div = d+i;
    		document.getElementById(d+i).innerHTML="";
     		document.getElementById(d+i).style.cursor="default";
    	}
        for (i = x.getDay(); i < (daysPerMonth(dateX.getMonth())+x.getDay()); i++){
            document.getElementById(d+i).innerHTML=ctr;
    		document.getElementById(d+i).style.cursor="pointer";
            ctr++;
        }
        document.getElementById('Month').innerHTML=(months[dateX.getMonth()] + " " + dateX.getFullYear());
    }

    Can anyone tell me what I am doing wrong? Here is the rest of the code:

    Code:
    <?php
    function getURLDate(){
    	if (isset($_REQUEST['yyyy'], $_REQUEST['mm'], $_REQUEST['dd'])){
    		$yyyy = $_REQUEST['yyyy'];
    		$mm = $_REQUEST['mm'];
    		$dd = $_REQUEST['dd'];
    		echo'
    		date = new Date('.$yyyy.','.$mm.','.$dd.');  
    		displayMini(date);
    		';
    		
    	}else{
    		echo'
    		date = new Date();
    		displayMini(date);
    		';
    	}
    }
    ?>	
    
    
    <html>
    <head>
    <script language="javascript">
    function daysPerMonth(month){
        switch(month){
        case 0:
            return 31;
            break;
        case 1:
            if(month%4 == 0 && !(month%100 == 0 && !(month%400 == 0))){return 29;}else{return 28;}
            break;
        case 2:
            return 31;
            break;
        case 3:
            return 30;
            break;
        case 4:
            return 31;
            break;
        case 5:
            return 30;
            break;
        case 6:
            return 31;
            break;
        case 7:
            return 31;
            break;
        case 8:
            return 30;
            break;
        case 9:
            return 31;
            break;
        case 10:
            return 30;
            break;
        case 11:
            return 31;
            break;
        default:
            return 00;
        }
    }
    var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    
    <?php getURLDate(); ?>
    
    function updateNextMonth(){
        var yyyy = date.getFullYear();
        var mm = date.getMonth();
        var dd = date.getDay();
      
        if(mm == 11){
            mm = 0;
            yyyy = date.getFullYear()+1;
        }
        else{
            mm++;
        }
      
        date = new Date(yyyy,mm,dd);  
        displayMini(date);
    }  
    
    function updatePrevMonth(){
        var yyyy = date.getFullYear();
        var mm = date.getMonth();
        var dd = date.getDay();
      
        if(mm == 0){
            mm = 12;
            yyyy = date.getFullYear()-1;
        }
        else{
            mm--;
        }
      
        date = new Date(yyyy,mm,dd);  
        displayMini(date);
    }
    
    function displayMini(dateX){
    	var x = new Date(dateX.getFullYear(),dateX.getMonth(),1);
    	var i = 0;
    	var d = 'd';
    	var ctr = 1;
    	for (i = 0; i < 42; i++){
    		div = d+i;
    		document.getElementById(d+i).innerHTML="";
     		document.getElementById(d+i).style.cursor="default";
    	}
        for (i = x.getDay(); i < (daysPerMonth(dateX.getMonth())+x.getDay()); i++){
            document.getElementById(d+i).innerHTML=ctr;
    		document.getElementById(d+i).style.cursor="pointer";
            ctr++;
        }
        document.getElementById('Month').innerHTML=(months[dateX.getMonth()] + " " + dateX.getFullYear());
    }
    
    function submit_miniCalendar(dd){
    	document.getElementById("fmYYYY").value = date.getFullYear();
    	document.getElementById("fmMM").value = date.getMonth();
        document.getElementById("fmDD").value = dd;
        document.miniCalendar.submit();
      }
    
    
    
    </script>    
     
    <style>
    #Left{position:absolute;left:0px;top:0px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;cursor: pointer;}
    #Month{position:absolute;left:20px;top:0px;width:100px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #Right{position:absolute;left:120px;top:0px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;cursor: pointer;}
    
    #SU{position:absolute;left:0px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #MO{position:absolute;left:20px;top:20px;width:22px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #TU{position:absolute;left:40px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #WE{position:absolute;left:60px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #TH{position:absolute;left:80px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #FR{position:absolute;left:100px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #SA{position:absolute;left:120px;top:20px;width:20px;height:20px;border-bottom:#000000 1px solid;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d0{position:absolute;left:0px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d1{position:absolute;left:20px;top:45px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d2{position:absolute;left:40px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d3{position:absolute;left:60px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d4{position:absolute;left:80px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d5{position:absolute;left:100px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d6{position:absolute;left:120px;top:45px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d7{position:absolute;left:0px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d8{position:absolute;left:20px;top:65px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d9{position:absolute;left:40px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d10{position:absolute;left:60px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d11{position:absolute;left:80px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d12{position:absolute;left:100px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d13{position:absolute;left:120px;top:65px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d14{position:absolute;left:0px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d15{position:absolute;left:20px;top:85px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d16{position:absolute;left:40px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d17{position:absolute;left:60px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d18{position:absolute;left:80px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d19{position:absolute;left:100px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d20{position:absolute;left:120px;top:85px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d21{position:absolute;left:0px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d22{position:absolute;left:20px;top:105px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d23{position:absolute;left:40px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d24{position:absolute;left:60px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d25{position:absolute;left:80px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d26{position:absolute;left:100px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d27{position:absolute;left:120px;top:105px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d28{position:absolute;left:0px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d29{position:absolute;left:20px;top:125px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d30{position:absolute;left:40px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d31{position:absolute;left:60px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d32{position:absolute;left:80px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d33{position:absolute;left:100px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d34{position:absolute;left:120px;top:125px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    #d35{position:absolute;left:0px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d36{position:absolute;left:20px;top:145px;width:22px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d37{position:absolute;left:40px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d38{position:absolute;left:60px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d39{position:absolute;left:80px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d40{position:absolute;left:100px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    #d41{position:absolute;left:120px;top:145px;width:20px;height:20px;text-align:center;font-family:Arial, Helvetica, sans-serif;font-size:12px;}
    
    </style>
    </head>
    <body onLoad="displayMini(date);">  
    
    <form name="miniCalendar" action="test33333.php" method="POST">
      <input type="hidden" name="fmYYYY" value="">
      <input type="hidden" name="fmMM" value=""> 
      <input type="hidden" name="fmDD" value=""> 
    
    <div id="Left" onClick="updatePrevMonth();">&lt;</div>
    <div id="Month">&nbsp;</div>
    <div id="Right" onClick="updateNextMonth();">&gt;</div>
    <div id="SU">S</div>
    <div id="MO">M</div>
    <div id="TU">T</div>
    <div id="WE">W</div>
    <div id="TH">T</div>
    <div id="FR">F</div>
    <div id="SA">S</div>
    <div id="d0"></div>
    <div id="d1"></div>
    <div id="d2"></div>
    <div id="d3"></div>
    <div id="d4"></div>
    <div id="d5"></div>
    <div id="d6"></div>
    <div id="d7"></div>
    <div id="d8"></div>
    <div id="d9"></div>
    <div id="d10"></div>
    <div id="d11"></div>
    <div id="d12"></div>
    <div id="d13"></div>
    <div id="d14"></div>
    <div id="d15"></div>
    <div id="d16"></div>
    <div id="d17"></div>
    <div id="d18"></div>
    <div id="d19"></div>
    <div id="d20"></div>
    <div id="d21"></div>
    <div id="d22"></div>
    <div id="d23"></div>
    <div id="d24"></div>
    <div id="d25"></div>
    <div id="d26"></div>
    <div id="d27"></div>
    <div id="d28"></div>
    <div id="d29"></div>
    <div id="d30"></div>
    <div id="d31"></div>
    <div id="d32"></div>
    <div id="d33"></div>
    <div id="d34"></div>
    <div id="d35"></div>
    <div id="d36"></div>
    <div id="d37"></div>
    <div id="d38"></div>
    <div id="d39"></div>
    <div id="d40"></div>
    <div id="d41"></div>
    </form>
    </body>
    </html>
    Last edited by thespikeyone; 08-30-2008 at 08:16 AM. Reason: I resolved the issue myself.

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured out the problem. The function displayMini(dateX) was called twice when it only needed to be called once. I'm not sure why that wouldn't work and I don't really care as i did not mean to call it twice.

    I simply removed the call to the function in the PHP section of the code and now it works like a charm.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •