FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Help me for a dynamic calendar

 


alrofaee
Hi everyone

I have a problem with my dynamic calendar so I have to create two drop down menus the first is the first day of the month, the second menu is for the number of days. when I click on the "create calendar" button, I will get the calendar that I chose before. Moreover, when I click on a cell, it would be changed and the table style is same as zebra. I made the html and JavaScript, but it doesn't work.

This is a flash file which explain what I exactly I want :

http://www.alrofaeegraphics.com/Talal/DynamicCalendar9.swf

This is my code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic Calendar</title>
<style>
      *{
         padding:0;
         margin: 0;
      }
      html, body{
         text-align:center;
      }
      #wrapper{
         background-color:#fff;
         width: 750px;
         margin: 1px auto;
         text-align:left;
      }
      h1{
         color:#000000;
         font-family:Georgia, "Times New Roman", Times, serif;
         font-size:14px;
      }
      
      h2{
         color:#000000;
         font-family:Georgia, "Times New Roman", Times, serif;
         font-size:12px;
         text-align:center;
      }
      
      /* Default styles for form tags */
      form{
         margin: 20px;
         width: 600px;
         border: 1px solid #000;
         padding: 15px;
      }
      fieldset{
         /* the line around the form fields */
         color:#666;
         background-color:#eee;
         padding:12px;
      }
      legend{
         /* this is the label on top of the fieldset line */
         color:#000000;
         font-family:Georgia, "Times New Roman", Times, serif;
         font-size:14px;
         padding: 0 1em;
         margin:0 2em;
      }
      input, select, textarea{
         color:#000000;
         font-family:Georgia, "Times New Roman", Times, serif;
         font-size:14px;
         padding: 2px;
         vertical-align:middle;
      }
      optgroup{
         
      }
      option{
         padding-left:15px;
      }
      label{
         color:#000000;
         font-family:Georgia, "Times New Roman", Times, serif;
         font-size:14px;
         display: inline;
      }
      /* structural styles to control positioning of form elements */
      .FBox{
         /* formBox can be a div or a list item ... you choose what you feel is most appropriate */
         display:block;
         margin:4px;
      }
      .FBox label{
         /* style for label on top of field */
         display: block;
         padding:4px 0 3px 0;
      }
      .FBox input, .FBox select, .FBox textarea{
         /* Use margins instead of padding here. padding will create space inside the border of the input field */
         margin: 3px 0 4px 0;
      }
      
      /* The styles for the grouped radio buttons */
      .groupChoices{
         /* use this next line to create space for the main label to the left of all the choices */
         margin-left: 100px;
         overflow:hidden;
      }
      .fieldgroup{
         width: 120px;
         height:2em;
         float:left;
      }
      fieldset label.main{
         /* style for label to the left of the field */
         float:left;
         width:150px;
      }
      .fieldgroup label{
         /* style for label to the left of the field */
         display:inline;
      }
      .fieldgroup input{
         /* style for the labels and radio buttons beside each other */
         display:inline;
      }
      
      /* styles for sizing form elements */
      input.narrow, select.narrow, textarea.narrow{
         width: 50px;
      }
      input.mid, select.mid, textarea.mid{
         width: 150px;
      }
      input.wide, select.wide, textarea.wide{
         width: 300px;
      }
      input.xtrawide, select.xtrawide, textarea.xtrawide{
         width: 400px;
      }
      input.chk{
         /* special styles for checkboxes and radio buttons */
         width:auto;
      }
      input.btn{
         /* special styles for buttons */
         width:auto;
      }
      
      /* special effects */
      input:active, input:focus, select:active, select:focus, textarea:active, textarea:focus{
         background-color:#fc0;
         outline:1px dotted #f90;
      }
   </style>
   
   <script type="text/javascript">
   
   var objPrevElement = new Object();

function fToggleColor(myElement) {
var toggleColor = "#ff0000";
if (myElement.id == "calDateText") {
if (myElement.color == toggleColor) {
myElement.color = "";
} else {
myElement.color = toggleColor;
   }
} else if (myElement.id == "calCell") {
for (var i in myElement.children) {
if (myElement.children[i].id == "calDateText") {
if (myElement.children[i].color == toggleColor) {
myElement.children[i].color = "";
} else {
myElement.children[i].color = toggleColor;
            }
         }
      }
   }
}
function fSetSelectedDay(myElement){
if (myElement.id == "calCell") {
if (!isNaN(parseInt(myElement.children["calDateText"].innerText))) {
myElement.bgColor = "#c0c0c0";
objPrevElement.bgColor = "";
document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText);
objPrevElement = myElement;
      }
   }
}
function fGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function fBuildCal(iYear, iMonth, iDayStyle) {
var aMonth = new Array();
aMonth[0] = new Array(7);
aMonth[1] = new Array(7);
aMonth[2] = new Array(7);
aMonth[3] = new Array(7);
aMonth[4] = new Array(7);
aMonth[5] = new Array(7);
aMonth[6] = new Array(7);
var dCalDate = new Date(iYear, iMonth-1, 1);
var iDayOfFirst = dCalDate.getDay();
var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
var iVarDate = 1;
var i, d, w;
if (iDayStyle == 2) {
aMonth[0][0] = "Sunday";
aMonth[0][1] = "Monday";
aMonth[0][2] = "Tuesday";
aMonth[0][3] = "Wednesday";
aMonth[0][4] = "Thursday";
aMonth[0][5] = "Friday";
aMonth[0][6] = "Saturday";
} else if (iDayStyle == 1) {
aMonth[0][0] = "Sun";
aMonth[0][1] = "Mon";
aMonth[0][2] = "Tue";
aMonth[0][3] = "Wed";
aMonth[0][4] = "Thu";
aMonth[0][5] = "Fri";
aMonth[0][6] = "Sat";
} else {
aMonth[0][0] = "Su";
aMonth[0][1] = "Mo";
aMonth[0][2] = "Tu";
aMonth[0][3] = "We";
aMonth[0][4] = "Th";
aMonth[0][5] = "Fr";
aMonth[0][6] = "Sa";
}
for (d = iDayOfFirst; d < 7; d++) {
aMonth[1][d] = iVarDate;
iVarDate++;
}
for (w = 2; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (iVarDate <= iDaysInMonth) {
aMonth[w][d] = iVarDate;
iVarDate++;
      }
   }
}
return aMonth;
}
function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
var myMonth;
myMonth = fBuildCal(iYear, iMonth, iDayStyle);
document.write("<table border='1'>")
document.write("<tr>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][0] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][1] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][2] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][3] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][4] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][5] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][6] + "</td>");
document.write("</tr>");
for (w = 1; w < 7; w++) {
document.write("<tr>")
for (d = 0; d < 7; d++) {
document.write("<td align='left' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>");
if (!isNaN(myMonth[w][d])) {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>" + myMonth[w][d] + "</font>");
} else {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)> </font>");
}
document.write("</td>")
}
document.write("</tr>");
}
document.write("</table>")
}
function fUpdateCal(iYear, iMonth) {
myMonth = fBuildCal(iYear, iMonth);
objPrevElement.bgColor = "";
document.all.calSelectedDate.value = "";
for (w = 1; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (!isNaN(myMonth[w][d])) {
calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
} else {
calDateText[((7*w)+d)-7].innerText = " ";
         }
      }
   }
}
   
   </script>
</head>

<body>
   <div id="wrapper">
      <div id="form">
            <form name="CalendarForm" id="CalendarForm" action="#" method="" enctype="">
                  
                  <h1>Dynamic Calendar</h1>
                  <div class="FBox">
                   <label>First Day: </label>
                    <select name="FirstDay" id="FirstDay" class="wide">
                             <option value="Sunday">Sunday</option>
                            <option value="Monday">Monday</option>
                            <option value="Tuesday">Tuesday</option>
                            <option value="Wednesday">Wednesday</option>
                            <option value="Thursday">Thursday</option>
                            <option value="Friday">Friday</option>
                            <option value="Saturday">Saturday</option>
                    </select>
                </div>
            
            <div class="FBox">
                   <label>Number of Days: </label>
                    <select name="NumberDays" id="NumberDays" class="wide">
                             <option value="31">31</option>
                            <option value="30">30</option>
                            <option value="29">29</option>
                            <option value="28">28</option>
                    </select>
                </div>
            
            <div class="FBox">
                   <input type="submit" name="CreateCalenda" id="btnCC" value="Create Calenda" />
                </div>
            <h2>Click on a day to highlight it.</h2>
            <table width="100%" border="1">
                  <tr>
                    <td>Sunday</td>
                    <td>Monday</td>
                    <td>Tuesday</td>
                    <td>Wednesday</td>
                    <td>Thursday</td>
                    <td>Friday</td>
                    <td>Saturday</td>
                  </tr>
                </table>
            <p>&nbsp;</p>
            </form>
   
      </div>
   
   </div>

</body>
</html>


Can anyone help me with this code?
Stubru Freak
Can you put it online somewhere, so we can see what's going wrong?
alrofaee
^^

COPY THE CODE ABOVE TO THE Notepad then save as html

please, I nedd some helps
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.