I was wondering if someone could help me out. I am new to jscript and I need to modify a calendar onclick event. We have a calendar which displays the dates either in green or red based upon data from a string variable: - Valiable example: var t = tDate;
-
tDate = "4/10/2009,4/24/2009,5/8/2009,5/22/2009"
The code is written to find a date in the tDate string, then the day number is Green or Red.
My question is that the jscript makes all cells have an onclick event to place the selected date value in a list box. I would like to turn off the onclick event for any cell that is not in the tDate string. The attached code first draws the calendar with the current month days. Then if you change months the calendar will use a update function which is using (element.innert ext) update to change the values in the cells.
Any help would be greatly appreciated. Attached is the jscript code. - var dDate = new Date();
-
var dCurMonth = dDate.getMonth();
-
var dCurDayOfMonth = dDate.getDate();
-
var dCurYear = dDate.getFullYear();
-
var objPrevElement = new Object();
-
var arySelectedDays = new Array();
-
-
-
-
function fToggleColor(myElement) {
-
-
var toggleColor = "#0000ff";
-
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.toString().substr(0,myElement.id.toString().length-3) == "calCell") {
-
if (!isNaN(parseInt(myElement.children[0].innerText))) {
-
-
//toggles back ground color after click
-
myElement.bgColor = "#00FF00";
-
-
var strDay=myElement.children[0].innerText;
-
-
if(strDay.length<2) strDay="0"+strDay;
-
var strReturnDate = document.all.tbSelMonth.options[document.all.tbSelMonth.selectedIndex].value+"/"+strDay+"/"+document.all.tbSelYear.options[document.all.tbSelYear.selectedIndex].value
-
if(document.all.traDate.value.indexOf(strReturnDate,0)>-1){
-
myElement.bgColor="";
-
document.all.traDate.value = document.all.traDate.value.substr(0,document.all.traDate.value.indexOf(strReturnDate,0)) + document.all.traDate.value.substr(document.all.traDate.value.indexOf(strReturnDate,0)+12,document.all.traDate.value.length);
-
}else{
-
document.all.traDate.value+=strReturnDate+"\n";
-
}
-
//objPrevElement.bgColor = "";
-
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] = "<font color=red>Sunday</font>";
-
aMonth[0][1] = "Monday";
-
aMonth[0][2] = "Tuesday";
-
aMonth[0][3] = "Wednesday";
-
aMonth[0][4] = "Thursday";
-
aMonth[0][5] = "Friday";
-
aMonth[0][6] = "<font color=red>Saturday</font>";
-
} else if (iDayStyle == 1) {
-
aMonth[0][0] = "<font color=red>Sun</font>";
-
aMonth[0][1] = "Mon";
-
aMonth[0][2] = "Tue";
-
aMonth[0][3] = "Wed";
-
aMonth[0][4] = "Thu";
-
aMonth[0][5] = "Fri";
-
aMonth[0][6] = "<font color=red>Sat</font>";
-
} else {
-
aMonth[0][0] = "<font color=red>Su</font>";
-
aMonth[0][1] = "Mo";
-
aMonth[0][2] = "Tu";
-
aMonth[0][3] = "We";
-
aMonth[0][4] = "Th";
-
aMonth[0][5] = "Fr";
-
aMonth[0][6] = "<font color=red>Sa</font>";
-
-
}
-
//Days of the month
-
for (d = iDayOfFirst; d < 7; d++) {
-
aMonth[1][d] = iVarDate;
-
//alert (iVarDate)
-
iVarDate++;
-
}
-
for (w = 2; w < 7; w++) {
-
for (d = 0; d < 7; d++) {
-
if (iVarDate <= iDaysInMonth) {
-
aMonth[w][d] = iVarDate;
-
iVarDate++;
-
//alert (iVarDate)
-
}
-
}
-
}
-
return aMonth;
-
}
-
function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
-
var myMonth;
-
//var iFontColor = "#000000"; //Black
-
var iFontColorGood = "#006600"; //Green
-
var iFontColorBad = "#FF0000"; //Red
-
var iFontWeight = "normal";
-
-
//Data from route calendar table
-
var t = tDate;
-
-
myMonth = fBuildCal(iYear, iMonth, iDayStyle);
-
document.write("<table border='1'>")
-
document.write("<tr>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][0] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][1] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][2] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][3] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][4] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][5] + "</td>");
-
document.write("<td align='center' bgcolor=#C0C0C0 style='FONT-FAMILY:Verdana;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_"+w+d+" style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>");
-
if (!isNaN(myMonth[w][d])) {
-
var sString = (tDate.search(iMonth+"/"+myMonth[w][d]+"/"+iYear)); //searches string for each date
-
if (sString>=0) {
-
document.write("<font id=calDateText onMouseOver='fToggleColor(this); window.status=this.id;' style='CURSOR:Hand;FONT-FAMILY:Verdana;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + ";COLOR:" + iFontColorGood + "' onMouseOut='fToggleColor(this)'>" + myMonth[w][d] + "</font>");
-
} else {
-
document.write("<font id=calDateText onMouseOver='fToggleColor(this); window.status=this.id;' style='CURSOR:Hand;FONT-FAMILY:Verdana;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + ";COLOR:" + iFontColorBad + "' onMouseOut='fToggleColor(this)'>" + myMonth[w][d] + "</font>");
-
}
-
-
} else {
-
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Verdana;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)')> </font>");
-
}
-
document.write("</td>")
-
}
-
document.write("</tr>");
-
}
-
document.write("</table>")
-
-
}
-
function fUpdateCal(iYear, iMonth) {
-
myMonth = fBuildCal(iYear, iMonth);
-
objPrevElement.bgColor = "";
-
for (w = 1; w < 7; w++) {
-
for (d = 0; d < 7; d++) {
-
if (!isNaN(myMonth[w][d])) {
-
var sString = (tDate.search(iMonth+"/"+myMonth[w][d]+"/"+iYear));
-
if (sString>=0) {
-
calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
-
calDateText[((7*w)+d)-7].style.color = 'green';
-
} else {
-
//calDateText[((7*w)+d)-7].innerText = myMonth[w][d] + "x";
-
calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
-
calDateText[((7*w)+d)-7].style.color = 'red';
-
//calDateText[((7*w)+d)-7].style.fontWeight = 'normal';
-
}
-
} else {
-
calDateText[((7*w)+d)-7].innerText = "";
-
}
-
}
-
}
-
}
-
function EnterToBR(strMEMO){
-
var str1=new String(strMEMO);
-
//alert (str1);
-
var str2 = "";
-
for(var i=0;i<str1.length;i++){
-
if(str1.charCodeAt(i)=="13")
-
str2=str2+"<br>";
-
//str2=str2+",";
-
else if(str1.charCodeAt(i)=="10")
-
str2=str2;
-
else
-
str2=str2+str1.charAt(i);
-
}
-
//alert(str2);
-
return (str2);
-
}
8 4134 JosAH 11,448
Recognized Expert MVP
This is a Javascript question; not a Java question. Those two languages don't have much in common. I'll move this thread to its correct forum.
kind regards,
Jos (moderator)
Of f f ! ...... So long code. It's not quite easy to read.
If you want to disable the onClick event. Either make the element disable or nullify the element onClick event handler. -
var element_ref = ....
-
element_ref.disabled = true;
-
-
-
element_ref = ....
-
element_ref = function(){} //nullify the event handler.
-
Dormilich 8,658
Recognized Expert Moderator Expert
about disabling event handlers: if you use addEventListene r* to attach the event you can remove it by removeEventList ener* - // attach event handler
-
element.addEventListener("click", yourFunction, false);
-
-
// remove event handler
-
element.removeEventListener("click", yourFunction, false);
* does not work in IE, use addEvent() for that (google)
@Dormilich
I think that would be attachEvent("on Click",handler) in IE.
acoder 16,027
Recognized Expert Moderator MVP
The code has so many problems, I almost wouldn't know where to start: - document.all - non-standard, few browsers support it
- innerText - not supported by all browsers, use innerHTML which has wider support
- The cursor property should be set to "pointer", not the non-standard "hand".
- <font> tags are deprecated - use CSS instead
There's probably more things, but I only took a brief look.
Dormilich 8,658
Recognized Expert Moderator Expert @dmjpro
sure, but you need a function that works both in IE an the standard compliant browsers (why making a function of your own if there are well tried functions available?)
@acoder
Why did you say "innerText" is not supported by all browsers? I knew those which are text node support innerText.
Dormilich 8,658
Recognized Expert Moderator Expert @dmjpro
both my JavaScript resources (SelfHTML & MDC) say that innerText is not supported by Mozilla and Opera.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: ZubZero |
last post by:
Hello,
i have to write a utility in c++ for windows 2k/XP.
But i have 2 difficult problems.
I asked many programmers i know, but none of them was able to tell me
how i can do this.
1. I would like to disable a specific USB-port (not all ports, only
one).
I have a USB Cardreader with an integrated 7-port USB-Hub.
|
by: Bob Bedford |
last post by:
I create checkboxes using datas from a database (with PHP).
I store all values in an array, as I must pass this value like a Form value.
Now, in some cases, when a checkbox is selected, I must disactivate other
checkboxes.
How can I do this ?
here is the code:
|
by: Forti2ude |
last post by:
Hello,
I have a simple form...
<form>
<select name="foo" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
|
by: Rich |
last post by:
Hello,
So I would like to disable a textbox on a vb.net form
without the text getting grayed out. In vb6 I could place
a textbox control on a frame control and disable the frame
leaving the textbox enabled and text/background were
intact but mouse cursor remained an arraw (as opposed to
an I for editable). I tried a Panel control on my .net
form since I could I guess there is no longer a frame
control (also tried a groupbox control)....
|
by: |
last post by:
hi, how to disable the controls in page? thanks
For each myControl in Page.Controls
'want to disable myControl?
Next
| |
by: Jon |
last post by:
Hi,
I used XslCompiledTransform with the following Xsl file. The <xsl:text
disable-output-escaping="yes"does not work when using XslCompiledTransform
to do the trnasform (namely the output contain < not <), while it works when
using MSXML2 to do the transform. Does anyone have the same problem and how
to make the escape work? Thanks.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
by: Phoe6 |
last post by:
Hi all,
I am trying to disable the NIC card (and other cards) enabled in my
machine to test diagnostics on that card.
I am trying to disable it programmatic using python. I checked python
wmi and i could not find ways to disable/enable, (listing is however,
possible).
Where should I look for to enable/disable devices in python.
Thanks,
|
by: sainiranji |
last post by:
Hi All
I have diffrent categories in diffrrent logging purpose and all are working fine...but now my requirment is to disable all at once .
The below are change i did for disable all logges
! Observe log4j parsing this file
log4j.debug=false
|
by: David Henderson |
last post by:
I know 'disable-output-escaping' has been discussed in the past, but I can't
put my finger on any of the threads to see if my current problem is
addressed. Sorry for re-asking the question if it has already been
answered...
I have an XML doc that I am transforming via XSLT and JavaScript in the
browser. This allows me to return unsorted data to the browser and allow
the user to sort it with a mouseclick and not hit the server just...
|
by: nagmvs |
last post by:
Hi,
Can any one tell me How to disable Keyboard Functions using JavaScript.If knows please tell me the code.Also tell me the code for mouse disable also.
Thanks,
Nagesh.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |