JavaScript - Help With Calendar Date Disabling
Hey all i have this piece of code before that disables the given dates i put into an array. This works great for day 2-30 (out of a 31 day month) but it does not seem to work when i select either day 1 or day 31.
For day 1 it blocks out day 1 and i do not want that. The user should be able to select that day since it was selected. It does not do this for any other day. If the user selects day 2 then day 2 is selected on the calender and is not blocked. As for day 31, i don't know whats wrong with it because it never shows me an error. It's the type of error that shuts down the website with "System Unavailable" for about a minute before i can connect to the page again. Here is my code: Code: var disabledDays = ['3-31-2010','3-30-2010','3-29-2010','3-28-2010','3-27-2010','3-26-2010','3-25-2010','3-24-2010','3-23-2010','3-22-2010','3-21-2010','3-20-2010','3-19-2010','3-18-2010','3-17-2010','3-16-2010','3-15-2010','3-14-2010','3-13-2010','3-12-2010','3-11-2010','3-10-2010','3-9-2010','3-8-2010','3-7-2010','3-6-2010','3-05-2010']; function nationalDays(date) { var m = date.getMonth(), d = date.getDate(), y = date.getFullYear(); //console.log('Checking (raw): ' + m + '-' + d + '-' + y); for (i = 0; i < disabledDays.length; i++) { if(ArrayContains(disabledDays,(m+1) + '-' + d + '-' + y) || new Date() > date) { //console.log('bad: ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]); return [false]; } } //console.log('good: ' + (m+1) + '-' + d + '-' + y); return [true]; } function noWeekendsOrHolidays(date) { return nationalDays(date); } function ArrayIndexOf(array,item,from){ var len = array.length; for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){ if (array[i] === item) return i; } return -1; } function ArrayContains(array,item,from){ return ArrayIndexOf(array,item,from) != -1; } Any help would be great! David Similar TutorialsHello, I am a newbie to this forum. I have searched for the problem that I have in this forum but found none. I am creating a calendar using html/css and javascript. I used one the free javascript for calendar on the internet and modified it to the way I wanted it to be. However, I could not write the if statement so that the calendar will highlight the current date of the current month only, not all 12 months. And I could not write the if statement so that the calendar will know what day is a holiday and make it red color. Here is my code: Code: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>My Calendar</title> <style type="text/css"> #left {position:absolute;left:40px;top:10px;} #right {position:absolute;left:400px;top:10px;} .table1 {border-collapse:collapse;background-color:#efefef;} .th2 {height:10px;background-color:#eeeee0;color:#951159;font-size:10px;} .sunday {background-color:#DD2211;font-size:10px;font-weight:bold;color:ivory;width:20px;height:8px;} .day {background-color:navy;font-size:10px;font-weight:bold;color:ivory;width:20px;height:8px;} .date0 {border:1px solid #cccccc;font-size:10px;color:red;font-weight:bold;text-align:center;} /* This is the color for Sundays and Holidays */ .date1 {border:1px solid #cccccc;font-size:10px;height:10px;font-weight:bold;text-align:center;} /* This is the color for regular days */ .today {border:1px solid #cccccc;font-size:10px; color:#0000ff;background-color:#daffee;} /* This is the color for current day */ </style> </head> <body bgcolor=#cccccc> <div id="left"> <script> var i=0; for (i=0;i<=5;i++) { function leapYear(year) { if (year % 4 == 0) // basic rule return true // is leap year /* else */ // else not needed when statement is "return" return false // is not leap year } function getDays(month, year) { // create array to hold number of days in each month var ar = new Array(12) ar[0] = 31 // January ar[1] = (leapYear(year)) ? 29 : 28 // February ar[2] = 31 // March ar[3] = 30 // April ar[4] = 31 // May ar[5] = 30 // June ar[6] = 31 // July ar[7] = 31 // August ar[8] = 30 // September ar[9] = 31 // October ar[10] = 30 // November ar[11] = 31 // December // return number of days in the specified month (parameter) return ar[month] } function getMonthName(month) { // create array to hold name of each month var ar = new Array( "JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE", "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER") // return name of specified month (parameter) return ar[month] } setCal() function setCal() { // standard time attributes var now = new Date() var year = now.getFullYear() var current_month = now.getMonth() var date = now.getDate() now = null var month = i var monthName = getMonthName(month) // create instance of first day of month, and extract the day on which it occurs var firstDayInstance = new Date(year, month, 1) var firstDay = firstDayInstance.getDay() firstDayInstance = null // number of days in current month var days = getDays(month, year) // call function to draw calendar drawCal(firstDay + 1, days, date, monthName, year) } function drawCal(firstDay, lastDate, date, monthName, year) { // create basic table structure var text = "" // initialize accumulative variable to empty string text += '<CENTER>' text += '<TABLE class="table1">' // table settings text += '<TH COLSPAN=7 class="th2">' text += monthName + ' ' + year text += '</TH>' // close header cell // create array of abbreviated day names var weekDay = new Array("SUN", "MON","TUE","WED", "THU", "FRI", "SAT") // create first row of table to set column width and specify week day text += '<TR ALIGN="center" VALIGN="center">' for (var dayNum = 0; dayNum < 7; ++dayNum) { if (dayNum == 0) { text += '<TD class="sunday">' + weekDay[dayNum] + '</TD>' } else { text += '<TD class="day">' + weekDay[dayNum] + '</TD>' } } text += '</TR>' // declaration and initialization of two variables to help with tables var digit = 1 var curCell = 1 for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) { text += '<TR ALIGN="left" VALIGN="top">' for (var col = 1; col <= 7; ++col) { if (digit > lastDate) break if (curCell < firstDay) { text += '<TD></TD>'; curCell++ } else { if (col ==1) { // This is to make the text color red if it is Sunday text += '<TD class="date0">' + digit + '</TD>' } else /* if ((month ==1) && (col ==2) && (row==3)) { // This is to make the text color red if it is a holiday text += '<TD class="date0">' + digit + '</TD>' } else */ /* if (digit == date) { // current cell represent today's date text += '<TD class="today">' text += digit text += '</TD>' } else */ text += '<TD class="date1">' + digit + '</TD>' digit++ } } text += '</TR>' } // close all basic table tags text += '</TABLE>' text += '</CENTER>' // print accumulative HTML string document.write(text) } } </script> </div> <!-- #################################################################### --> <div id="right"> <script> var i=0; for (i=0;i<=5;i++) { function leapYear(year) { if (year % 4 == 0) // basic rule return true // is leap year /* else */ // else not needed when statement is "return" return false // is not leap year } function getDays(month, year) { // create array to hold number of days in each month var ar = new Array(12) ar[0] = 31 // January ar[1] = (leapYear(year)) ? 29 : 28 // February ar[2] = 31 // March ar[3] = 30 // April ar[4] = 31 // May ar[5] = 30 // June ar[6] = 31 // July ar[7] = 31 // August ar[8] = 30 // September ar[9] = 31 // October ar[10] = 30 // November ar[11] = 31 // December // return number of days in the specified month (parameter) return ar[month] } function getMonthName(month) { // create array to hold name of each month var ar = new Array( "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER") // return name of specified month (parameter) return ar[month] } setCal() function setCal() { // standard time attributes var now = new Date() var year = now.getFullYear() var current_month = now.getMonth() var date = now.getDate() now = null var month = i var monthName = getMonthName(month) // create instance of first day of month, and extract the day on which it occurs var firstDayInstance = new Date(year, month, 1) var firstDay = firstDayInstance.getDay() firstDayInstance = null // number of days in current month var days = getDays(month, year) // call function to draw calendar drawCal(firstDay + 1, days, date, monthName, year) } function drawCal(firstDay, lastDate, date, monthName, year) { // create basic table structure var text = "" // initialize accumulative variable to empty string text += '<CENTER>' text += '<TABLE class="table1">' // table settings text += '<TH COLSPAN=7 class="th2">' text += monthName + ' ' + year text += '</TH>' // close header cell // create array of abbreviated day names var weekDay = new Array("SUN", "MON","TUE","WED", "THU", "FRI", "SAT") // create first row of table to set column width and specify week day text += '<TR ALIGN="center" VALIGN="center">' for (var dayNum = 0; dayNum < 7; ++dayNum) { if (dayNum == 0) { text += '<TD class="sunday">' + weekDay[dayNum] + '</TD>' } else { text += '<TD class="day">' + weekDay[dayNum] + '</TD>' } } text += '</TR>' // declaration and initialization of two variables to help with tables var digit = 1 var curCell = 1 for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) { text += '<TR ALIGN="left" VALIGN="top">' for (var col = 1; col <= 7; ++col) { if (digit > lastDate) break if (curCell < firstDay) { text += '<TD></TD>'; curCell++ } else { if (col ==1) { // This is to make the text color red if it is Sunday text += '<TD class="date0">' + digit + '</TD>' } else /* if ((month ==1) && (col ==2) && (row==3)) { // This is to make the text color red if it is a holiday text += '<TD class="date0">' + digit + '</TD>' } else */ /* if (digit == date) { // current cell represent today's date text += '<TD class="today">' text += digit text += '</TD>' } else */ text += '<TD class="date1">' + digit + '</TD>' digit++ } } text += '</TR>' } // close all basic table tags text += '</TABLE>' text += '</CENTER>' // print accumulative HTML string document.write(text) } } </script> </div> </body> </html> This is just for my practice in html/css and javascript. Thanks for all your time and support. kvkt Hi all, I'm using the Epoch calendar at: http://www.javascriptkit.com/script/...ch/index.shtml It works great and does exactly what I need. I'm using it in flat mode so that it can be displayed statically on the page. What I can't seem to work out is how to retrieve the selected date once clicked on. I need to be able to print the output in dd/mm/yyyy format, either on screen or in an alert or something similar. If anyone has worked with this calendar and knows how to do it, or can sort it, I'd appreciate it greatly. I can't paste code here as it's too long, but the source code on the site linked above is exactly the same as I'm using. Cheers! I have a calendar and when selecting the date the date format inserted to text box is in the format ' 10/10/2010'. This is not getting inserted into oracle database. Oracle accepts only the format '10-OCT-10' . So please help me to change the format of date that getting selected from calendar. Code is given below (calendar.html, calendar.js & style.css) //calendar.html Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="standard.css" type="text/css" /> <script type="text/javascript" src="calendar.js"></script> <title>CALENDAR</title> </head> <body> <label>Date : </label><input name="startdate" type="text" onClick="displayDatePicker('startdate')"> <script type="text/javascript"> window.onLoad(displayDatePicker('ADate')); </script></body></html> //calendar.js Code: var datePickerDivID = "datepicker"; var iFrameDivID = "datepickeriframe"; var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'); var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'); var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); // these variables define the date formatting we're expecting and outputting. // If you want to use a different format by default, change the defaultDateSeparator // and defaultDateFormat variables either here or on your HTML page. var defaultDateSeparator = "/"; // common values would be "/" or "." var defaultDateFormat = "dmy" // valid values are "mdy", "dmy", and "ymd" var dateSeparator = defaultDateSeparator; var dateFormat = defaultDateFormat; function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep) { var targetDateField = document.getElementsByName (dateFieldName).item(0); // if we weren't told what node to display the datepicker beneath, just display it // beneath the date field we're updating if (!displayBelowThisObject) displayBelowThisObject = targetDateField; // if a date separator character was given, update the dateSeparator variable if (dtSep) dateSeparator = dtSep; else dateSeparator = defaultDateSeparator; // if a date format was given, update the dateFormat variable if (dtFormat) dateFormat = dtFormat; else dateFormat = defaultDateFormat; var x = displayBelowThisObject.offsetLeft; var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ; // deal with elements inside tables and such var parent = displayBelowThisObject; while (parent.offsetParent) { parent = parent.offsetParent; x += parent.offsetLeft; y += parent.offsetTop ; } drawDatePicker(targetDateField, x, y); } /** Draw the datepicker object (which is just a table with calendar elements) at the specified x and y coordinates, using the targetDateField object as the input tag that will ultimately be populated with a date. This function will normally be called by the displayDatePicker function. */ function drawDatePicker(targetDateField, x, y) { var dt = getFieldDate(targetDateField.value ); // the datepicker table will be drawn inside of a <div> with an ID defined by the // global datePickerDivID variable. If such a div doesn't yet exist on the HTML // document we're working with, add one. if (!document.getElementById(datePickerDivID)) { // don't use innerHTML to update the body, because it can cause global variables // that are currently pointing to objects on the page to have bad references //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>"; var newNode = document.createElement("div"); newNode.setAttribute("id", datePickerDivID); newNode.setAttribute("class", "dpDiv"); newNode.setAttribute("style", "visibility: hidden;"); document.body.appendChild(newNode); } // move the datepicker div to the proper x,y coordinate and toggle the visiblity var pickerDiv = document.getElementById(datePickerDivID); pickerDiv.style.position = "absolute"; pickerDiv.style.left = x + "px"; pickerDiv.style.top = y + "px"; pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible"); pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block"); pickerDiv.style.zIndex = 10000; // draw the datepicker table refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate()); } /** This is the function that actually draws the datepicker calendar. */ function refreshDatePicker(dateFieldName, year, month, day) { // if no arguments are passed, use today's date; otherwise, month and year // are required (if a day is passed, it will be highlighted later) var thisDay = new Date(); if ((month >= 0) && (year > 0)) { thisDay = new Date(year, month, 1); } else { day = thisDay.getDate(); thisDay.setDate(1); } // the calendar will be drawn as a table // you can customize the table elements with a global CSS style sheet, // or by hardcoding style and formatting elements below var crlf = "\r\n"; var TABLE = "<table cols=7 class='dpTable'>" + crlf; var xTABLE = "</table>" + crlf; var TR = "<tr class='dpTR'>"; var TR_title = "<tr class='dpTitleTR'>"; var TR_days = "<tr class='dpDayTR'>"; var TR_todaybutton = "<tr class='dpTodayButtonTR'>"; var xTR = "</tr>" + crlf; var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' "; // leave this tag open, because we'll be adding an onClick event var TD_title = "<td colspan=5 class='dpTitleTD'>"; var TD_buttons = "<td class='dpButtonTD'>"; var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>"; var TD_days = "<td class='dpDayTD'>"; var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' "; // leave this tag open, because we'll be adding an onClick event var xTD = "</td>" + crlf; var DIV_title = "<div class='dpTitleText'>"; var DIV_selected = "<div class='dpDayHighlight'>"; var xDIV = "</div>"; // start generating the code for the calendar table var html = TABLE; // this is the title bar, which displays the month and the buttons to // go back to a previous month or forward to the next month html += TR_title; html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "<") + xTD; html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD; html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, ">") + xTD; html += xTR; // this is the row that indicates which day of the week we're on html += TR_days; for(i = 0; i < dayArrayShort.length; i++) html += TD_days + dayArrayShort[i] + xTD; html += xTR; // now we'll start populating the table with days of the month html += TR; // first, the leading blanks for (i = 0; i < thisDay.getDay(); i++) html += TD + " " + xTD; // now, the days of the month do { dayNum = thisDay.getDate(); TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">"; if (dayNum == day) html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD; else html += TD + TD_onclick + dayNum + xTD; // if this is a Saturday, start a new row if (thisDay.getDay() == 6) html += xTR + TR; // increment the day thisDay.setDate(thisDay.getDate() + 1); } while (thisDay.getDate() > 1) // fill in any trailing blanks if (thisDay.getDay() > 0) { for (i = 6; i > thisDay.getDay(); i--) html += TD + " " + xTD; } html += xTR; // add a button to allow the user to easily return to today, or close the calendar var today = new Date(); var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate(); html += TR_todaybutton + TD_todaybutton; html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> "; html += xTD + xTR; // and finally, close the table html += xTABLE; document.getElementById(datePickerDivID).innerHTML = html; // add an "iFrame shim" to allow the datepicker to display above selection lists adjustiFrame(); } /** Convenience function for writing the code for the buttons that bring us back or forward a month. */ function getButtonCode(dateFieldName, dateVal, adjust, label) { var newMonth = (dateVal.getMonth () + adjust) % 12; var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12); if (newMonth < 0) { newMonth += 12; newYear += -1; } return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>"; } /** Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator variables at the beginning of this script library. */ function getDateString(dateVal) { var dayString = "00" + dateVal.getDate(); var monthString = "00" + (dateVal.getMonth()+1); dayString = dayString.substring(dayString.length - 2); monthString = monthString.substring(monthString.length - 2); switch (dateFormat) { case "dmy" : return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear(); case "ymd" : return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString; case "mdy" : default : return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear(); } } /** Convert a string to a JavaScript Date object. */ function getFieldDate(dateString) { var dateVal; var dArray; var d, m, y; try { dArray = splitDateString(dateString); if (dArray) { switch (dateFormat) { case "dmy" : d = parseInt(dArray[0], 10); m = parseInt(dArray[1], 10) - 1; y = parseInt(dArray[2], 10); break; case "ymd" : d = parseInt(dArray[2], 10); m = parseInt(dArray[1], 10) - 1; y = parseInt(dArray[0], 10); break; case "mdy" : default : d = parseInt(dArray[1], 10); m = parseInt(dArray[0], 10) - 1; y = parseInt(dArray[2], 10); break; } dateVal = new Date(y, m, d); } else if (dateString) { dateVal = new Date(dateString); } else { dateVal = new Date(); } } catch(e) { dateVal = new Date(); } return dateVal; } /** Try to split a date string into an array of elements, using common date separators. If the date is split, an array is returned; otherwise, we just return false. */ function splitDateString(dateString) { var dArray; if (dateString.indexOf("/") >= 0) dArray = dateString.split("/"); else if (dateString.indexOf(".") >= 0) dArray = dateString.split("."); else if (dateString.indexOf("-") >= 0) dArray = dateString.split("-"); else if (dateString.indexOf("\\") >= 0) dArray = dateString.split("\\"); else dArray = false; return dArray; } function updateDateField(dateFieldName, dateString) { var targetDateField = document.getElementsByName (dateFieldName).item(0); if (dateString) targetDateField.value = dateString; var pickerDiv = document.getElementById(datePickerDivID); pickerDiv.style.visibility = "hidden"; pickerDiv.style.display = "none"; adjustiFrame(); targetDateField.focus(); // after the datepicker has closed, optionally run a user-defined function called // datePickerClosed, passing the field that was just updated as a parameter // (note that this will only run if the user actually selected a date from the datepicker) if ((dateString) && (typeof(datePickerClosed) == "function")) datePickerClosed(targetDateField); } /** Use an "iFrame shim" to deal with problems where the datepicker shows up behind selection list elements, if they're below the datepicker. The problem and solution are described at: http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx */ function adjustiFrame(pickerDiv, iFrameDiv) { // we know that Opera doesn't like something about this, so if we // think we're using Opera, don't even try var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); if (is_opera) return; // put a try/catch block around the whole thing, just in case try { if (!document.getElementById(iFrameDivID)) { // don't use innerHTML to update the body, because it can cause global variables // that are currently pointing to objects on the page to have bad references //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>"; var newNode = document.createElement("iFrame"); newNode.setAttribute("id", iFrameDivID); newNode.setAttribute("src", "javascript:false;"); newNode.setAttribute("scrolling", "no"); newNode.setAttribute ("frameborder", "0"); document.body.appendChild(newNode); } if (!pickerDiv) pickerDiv = document.getElementById(datePickerDivID); if (!iFrameDiv) iFrameDiv = document.getElementById(iFrameDivID); try { iFrameDiv.style.position = "absolute"; iFrameDiv.style.width = pickerDiv.offsetWidth; iFrameDiv.style.height = pickerDiv.offsetHeight ; iFrameDiv.style.top = pickerDiv.style.top; iFrameDiv.style.left = pickerDiv.style.left; iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1; iFrameDiv.style.visibility = pickerDiv.style.visibility ; iFrameDiv.style.display = pickerDiv.style.display; } catch(e) { } } catch (ee) { } } //style.css Code: body { margin:5px 5px; font-size:0.9em; font-family: "Myriad Pro", "Trebuchet MS", Arial; font-size:14px; border:1px solid #000; background-color:#CCCCFF;} a { color:#64a520; text-decoration:none;} a:hover { text-decoration:underline;} /*Calendar Styles*/ /* the div that holds the date picker calendar */ .dpDiv { } /* the table (within the div) that holds the date picker calendar */ .dpTable { font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; color:#000000; background-color:#99CCCC; border: 1px solid #AAAAAA; } /* a table row that holds date numbers (either blank or 1-31) */ .dpTR { } /* the top table row that holds the month, year, and forward/backward buttons */ .dpTitleTR { } /* the second table row, that holds the names of days of the week (Mo, Tu, We, etc.) */ .dpDayTR { } /* the bottom table row, that has the "This Month" and "Close" buttons */ .dpTodayButtonTR { } /* a table cell that holds a date number (either blank or 1-31) */ .dpTD { border: 1px solid #ece9d8; } /* a table cell that holds a highlighted day (usually either today's date or the current date field value) */ .dpDayHighlightTD { background-color: #CCCCCC; border: 1px solid #AAAAAA; } /* the date number table cell that the mouse pointer is currently over (you can use contrasting colors to make it apparent which cell is being hovered over) */ .dpTDHover { background-color: #aca998; border: 1px solid #888888; cursor: pointer; color: red; } /* the table cell that holds the name of the month and the year */ .dpTitleTD { } /* a table cell that holds one of the forward/backward buttons */ .dpButtonTD { } /* the table cell that holds the "This Month" or "Close" button at the bottom */ .dpTodayButtonTD { } /* a table cell that holds the names of days of the week (Mo, Tu, We, etc.) */ .dpDayTD { background-color: #CCCCCC; border: 1px solid #AAAAAA; color: white; } /* additional style information for the text that indicates the month and year */ .dpTitleText { font-size: 12px; color: gray; font-weight: bold; } /* additional style information for the cell that holds a highlighted day (usually either today's date or the current date field value) */ .dpDayHighlight { color: 4060ff; font-weight: bold; } /* the forward/backward buttons at the top */ .dpButton { font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10px; color: gray; background: #d8e8ff; font-weight: bold; padding: 0px; } /* the "This Month" and "Close" buttons at the bottom */ .dpTodayButton { font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10px; color: gray; background: #d8e8ff; font-weight: bold; } Hello everyone, I am creating a small application for my memory book. I want to have one of those calendars like in Here .. that would retutn values like: day month year - seperatelly that I could use in php. Im looking for easy solution if there is one.. Simple and short script Kind regards, Aurimas Hi, I have 2 calendars using jquery UI datepicker. The first calendar is default to todays date. What I need to happen is for the second calendar default date to change to default date (of first calendar) + 1 day. I'm really not too sure how to do this... So any help would be great! This is the code I have so far: [CODE] $(document).ready(function(){ $("#startDate").datepicker({ dateFormat: "dd/mm/yy" }).val() $('#startDate').datepicker('setDate', new Date()); }); $(document).ready(function(){ $("#endDate").datepicker({ dateFormat: "dd/mm/yy" }).val() }); $('#startDate').datepicker({onSelect: function(dateStr) { $('#endDate').datepicker('option', 'defaultDate', dateStr); }}); $('#endDate').datepicker(); [/ICODE] Hey I got two text boxes one for start date and second for end date in that i want to fill text boxes according to Quarter of a year, as like if i put 1-4-2012 in first text box then in second text box values should be automatically 30-6-2012. So now tell me please how to do this ??????? Regards rajboy13 Contact me @ = rajboy13@gmail.com irst post here, i'll try to be simple: I need to create a form where participants of a medical convention register to classes, each class lasts 3 hours, so a person who wants to attend to class starting at 10 am cannot register to 11 am, 12pm and 1pm classes, but he can register to 2pm and so on. There are 3 different classes per hour. i thought doing this using javascript, but i'm absolutely lost. Can you please give me a hint on how to do this? Thanks!! this is the part of the form that has the checkboxes. <form method="post" action="process.php"></form> <input type="checkbox" value="101" name="convention1"> 10 am: Cariovascular desease<br> <input type="checkbox" value="102" name="convention2"> 10 am: Changes on toracic surgeon<br> <input type="checkbox" value="103" name="convention3"> 10 am: New drugs on heart<br> <input type="checkbox" value="111" name="convention4"> 11 am: New drugs on heart (II)<br> <input type="checkbox" value="112" name="convention5"> 11 am: Dynamic process on blood pressure<br> <input type="checkbox" value="113" name="convention6"> 11 am: Aortic disease<br> <input type="checkbox" value="121" name="convention7"> 12 am: Pulmonar Pressure<br> <input type="checkbox" value="122" name="convention8"> 12 am: Open table<br> <input type="checkbox" value="131" name="convention9"> 1 pm: Neurological aspects on heart rate<br> <input type="checkbox" value="132" name="convention10"> 1 pm: Cardiovascular disease (II)<br> <input type="checkbox" value="133" name="convention11"> 1 pm: Mioresponse on heart failure<br> <input type="checkbox" value="141" name="convention12"> 2 pm<br> <input type="checkbox" value="142" name="convention13"> 2 pm<br> <input type="checkbox" value="143" name="convention14"> 2 pm<br> <input type="checkbox" value="151" name="convention15"> 3 pm<br> <input type="checkbox" value="152" name="convention16"> 3 pm<br> <input type="checkbox" value="153" name="convention17"> 3 pm<br> <input type="submit"></input> </form> Ok I just gota ask... I read this originally and nearly killed my self laughing... then my brain got the best of me and my curiosity took over... is it possible to write a javascript code that makes your web browser disable javascript? is it even possible for Javascript to access a web browser in that sort of fashion? Like can a script have that much control? ... or rather lack of control and self suicidal... but anyways Is it possible? So I've been working on this code for the day, and when I choose one radio button and click convert, it gives me the value and disables the box that shows the value. When I go to click the other radio button to do another conversion, it freezes up. I really am just trying to figure out how to make this code functionable whether you choose one radio button and do the conversion, or you want to do the other conversion without stalling out. I can't seem to find the bugs since I'm a newbie. Code: var $ = function (id) {//enables you to use $ instead of all the blah blah blah nonsense return document.getElementById(id); } var temperature = function (){//This function converts the value the user provides if($("to_celcius").checked == true)//if checked, then do this conversion { $("degrees_celcius").disabled = true; var far = parseFloat($("degrees_fahrenheit").value ); if(isNaN(far))//if its not a number then it gives the alert to enter a valid temperature { alert("Please enter a valid temperature.") return; } var far_cel =Math.round((far-32) * 5/9);//conversion assigned to variable $("degrees_celcius").value = far_cel; }else ($("to_fahrenheit").checked ==true)//if the other radio button isn't clicked, then this conversion { $("degrees_fahrenheit").disabled = true; var cell = parseFloat($("degrees_celcius").value); if(isNaN(cell))//if its not a number then it gives the alert to enter a valid temperature { alert("Please enter a valid temperature.") return; } var cel_far = Math.round(cell * 9/5 + 32); $("degrees_fahrenheit").value = cel_far;//conversion variable equals the value of text box "degrees_fahrenheit" } } function reset()//resets the text box fields { $("foofoo").reset(); } window.onload = function(){//handles all the onload activities $("convert").onclick = temperature; $("convert").onchange = temperature; //$("to_celcius").onchange = reset; //$("to_fahrenheit").onchange = reset; } Code: <body> <form id="foofoo" name="foofoo"> <div id="content"> <h1>Convert temperature</h1> <input type="radio" name="conversion_type" id="to_celcius" />From Fahrenheit to Celcius<br /> <input type="radio" name="conversion_type" id="to_fahrenheit" />From Celcius to Fahrenheit<br /> <br /> <label>Degrees Fahrenheit:</label> <input type="text" id="degrees_fahrenheit" name="cat" class="disabled" /><br /> <label>Degrees Celcius:</label> <input type="text" id="degrees_celcius" name="poo" class="disabled" /><br /> <br /> <input type="button" id="convert" value="Convert" /><br /> <br /> </div> </form> </body> What have I done wrong here? <INPUT id="purchase" onclick="document.getElementById("purchase").disabled = true;" type="submit" value="PURCHASE"> I need to disable some keys from their default behaviour in Google Chrome on Windows with javascript. The script below works for most keys but not for F10, left Windows key, right Windows key, NumLock and left Alt. (which are the keys I need to disable) Code: <script type="text/javascript"> addEventListener("keydown", function (event) { if(KeyID == 121 KeyID == 91 || KeyID == 92 || KeyID == 144|| KeyID == 18 ){ event.preventDefault(); } }, true); </script> I have also without luck tried event.stopPropagation () - event.cancelBubble = true - return false og void(). I would like to know if their is a solution or it simply isn't possible to disable the mentioned keys. Hi there, This is my request. I don't know if it CAN be done via JS, but it just seemed likely it could: Basically, I have a table echoed out by PHP: PHP Code: while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>".$row['Name']."</td>"; echo "<td>".$row['gig_count']."</td>"; echo "<td>" .$row['dob']."</td>"; echo "<td>".$row['Mail']."</td>"; echo "<td><a href=\"/records/add_gigs.php?id=".$row['Member_ID']."&?name=".$row['Name']."\"><button class=\"submit\">Add new Gig</button></a></td>"; echo "<td><a href=\"/certsend.php?name=".$row['Name']."&?mail=".$row['Mail']."\"><button class=\"submit\">Make Certificate!</button></a></td>"; echo "</tr>"; And if the value of gig_count is less than 20, then the 'make certificate' button will be disabled. Once gig_count is 20 or more, then it is re-enabled for that particular row. Any code towards this is greatly appreciated. Hi, I am using the jQuery UI Datepicker - Event Search. as a booking-system. I want to automatically disable days from my MYSQL table in my booking-system (datePicker). So, here is the deal: In my website, there is booking-system, you can reserve a room from datePicker. I have successfully created a PHP, which sends the information (name, room, date etc.) to my MYSQL. Then I have successfully created a datesonly.php, which prints only a dates from my MYSQL. So now I have to make javascript (?) which reads dates from datesonly.php and draws a booked-note to my datePicker at website (so people can see which days are booked --> no double-books!). Booked-note should be something like that day in datePicker is red. Thank you! And sorry for my bad english, I'm from Finland. EDIT: Sorry, the title should be: Disabling days from datePicker via JavaScript I'm using meta refresh to refresh my web page. I have a small compose email window that appears via ajax when the user clicks on a name. Is there a way I can disable the screen refresh in my ajax code while they are composing their message? Hi, I have a checkbox on a page which I have styled using some jquery code. I want the textbox underneath the checkbox to be disabled if the checkbox is ticked and enabled if it is unticked. I tried using javascript to do this but I beleive it didn't work because I have existing javascript/ jquery code on the page. Any help/advice would be fantastic, here is a link to the page : http://recipesuggester.co.uk/index.php Thankyou Hi, I am trying to submit a form in javascript on clicking 'Button1'.On submission,it will disable the html table 'HTMLTable1' present in it.The code which I am using is as: Code: function OnButton1_Click ( ) { var oRows = document.getElementById('HTMLTable1').getElementsByTagName('tr'); var irows = oRows.length ; if (confirm("Are you sure you want Submit?")) { for(k=1; k<=irows; k++) { if(document.getElementById("list"+k).selectedIndex == 0) { document.getElementById("list"+k).selectedIndex = 1; document.getElementById("list"+k).options[1].style.backgroundColor = "green"; } } Saver(); document.getElementById("HTMLTable1").disabled = true; } else{ alert("Submit cancelled!"); } } But On submit,the html table is getting disabled just for a moment then again it becomes active and user can interact with it.Can anyone tell me where this code is misbehaving? Thanks, Anil Hi everybody... I have some radio group boxes and according to select one of the values, the other values in another radio boxes should be enabled and checked. In the onClick method of each radiobox i call a setDefault() function to reset the value of radioboxes.... (e.g for (i;i<document.NPOrder.pSubstrate.length;i++){ document.NPOrder.pSubstrate[i].disabled=false; document.NPOrder.pSubstrate[i].checked=false; } and after that i disabled and checked the other's value...) Problem: The code in setDefault() doesn't work properly and after disabling the radios, i can't enable them again Please help me and thanks in advance... Hany Hi, I have a HTML table in a form with a submit button.In HTML table I have links present in first three rows for each columns of HTML table.I want to disable those links when user submit the form.How can I handle this in javascript? Please help. Thanks in advance. Anil. Not 100% sure why or how to make this work. I have 5 options in a select drop-down. Only two of them are to disable a text field. I have written it successfully to disable on one option. How would I add the second option? I have tried many different ways, and i know its something small that i am missing. Below is the code that does not work but shows the 2 options that disable my text field. Code: <script type="text/javascript"> function type_disable() { var qr_type = document.getElementById('qr_type'); var qr_owner = document.getElementById('qr_owner'); if(qr_type.value == 'bio' || 'rebrand') qr_owner.disabled = true else qr_owner.disabled = false } </script> Code: <tr> <td align="right"><span class="re">*</span>Type: </td> <td align="left"> <select id="qr_type" name="qr_type" onChange="type_disable()"> <option value="0">Select Type</option> <option value="property">Property Code</option> <option value="ipw">IPW Code</option> <option value="bio">Biography Code</option> <option value="rebrand">Rebrand Code</option> <option value="property_rebrand">Property-rebrand Code</option> </select> </td> <td ></td> </tr> <tr> <td align="right"><span class="re">*</span>Owner: </td> <td align="left"> <input type="textbox" name="qr_owner" id="qr_owner" size="30" value=""/></td> <td ></td> </tr> Thanks for any help! hi.. i have a jsp page in which there is a table. the number of rows is variable and depends on a pre-defined query. every row has 2 editable textboxes which are initially disabled. i need to activate these textboxes according to the radio button which corresponds to the particular row in question. can anybody pls tell me how to do that. the code that i have written is as follows.if there is any tweaking to be done pls suggest the same. code: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="java.util.ArrayList" %> <%@page import="DTO.UserGroupDTO"%> <html> <head> <script type="text/javascript">} funtion enable(){ document.getElementById("inp1").disabled=false; document.getElementById("inp2").disabled=false; } function disable(){ document.getElementById("inp1").disabled=true; document.getElementById("inp2").disabled=true; } </script> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Update User Group Inquiry Results</title> </head> <body bgcolor="#aabbcc"> <center> <h3>Update User Group Inquiry Results</h3><br><br> <%ArrayList arrayList=(ArrayList)request.getAttribute("myList"); ArrayList list; int size=arrayList.size(); Integer groupId=null; String userGroupName=null; String description=null; %> <form action="/test/BankServlet"> <table style="color: highlight" border="5"> <% if(!(arrayList.isEmpty())){%> <tr><th>Group ID</th><th>User Group Name</th><th>Description</th><th>Selection</th></tr> <% for(int i=0;i<size;i++){ UserGroupDTO userGroupDTO=(UserGroupDTO)arrayList.get(i); userGroupName=userGroupDTO.getUserGroupName(); groupId=userGroupDTO.getGroupId(); description=userGroupDTO.getDescription(); %> <tr> <td><%out.println(groupId); %></td> <td><input id="inp1" disabled="disabled" value="<% out.println(userGroupName); %>"></td> <td><input id="inp2" disabled="disabled" value="<%out.println(description); %>"> </td> <td> <input type="radio" name="radio2" value="<%=groupId %>" onclick="enable()"> </td> </tr> <% } } else{ out.println("No match found"); } %> <tr> <td><input type="hidden" name="strTitle" value="UpdateUserGroup"></td> </tr> <tr> <td><input type="hidden" name="value" value="<%=groupId%>"></td> </tr> </table><br> <input type="submit" value="Update User Group" style="background-color: gray"> </form> <form action="/test/jsp/UserGroup.jsp"> <input type="submit" value="Go Back to User Group Operations Page" style="background-color: gray"> </form> <br><br><br><br> </center> </body> </html> |