*mista*
10-24-2006, 02:10 PM
I am working with coldfusion and javascript. Am generating a dynamic table with class of each cell being "hdnvc". The cell names are serially 1,2,3 ... etc. When the user clicks on the cell, the javascript function calchg(sel) changes the class for that cell to "hdnvch". So far everything works perfect.
I have made another function (wcal()) which identifies which cell the user has clicked on by checking the class should be "hdnvch" and accordingly uses that cell name as a parameter for where the link should go. If the user has not selected any cell, which means all cells have the class "hdnvc", I have tried to put in a clause (else if ) that if the loop reaches the last cell without encountering any cell with class "hdnvch", then go to a different link. The moment I add this clause, the function starts ignoring the first clause (if) and always goes to the link in the second clause (else if). If I take off the clause (else if), the link goes to the parameter of the selected cell, but then if no cell is selected, the link doesn't work.
I am sure I am making a very obvious error in coding. I have no experience in javascript and I made these functions reading through this forum.
I will be very grateful for any advise, pointers, suggestions, guidance. The two functions are listed below. Thx in advance. Please ignore the coldfusion parameters enclosed within # #. They work alright.
<cfoutput>
<script type="text/javascript">
function calchg(sel) {
for (var i=1; i<32; i++) {
var theElement = document.getElementById(i);
if (i == sel) {
theElement.className = 'hdnvch';
}
else {
theElement.className = 'hdnvc';
}
}
}
</script>
<script type="text/javascript">
var thismonth;
thismonth = #DaysInMonth(CreateDate(url.ye,url.mo,1))#;
function wcal() {
for (var i=1; i<=thismonth; i++) {
var theElement = document.getElementById(i);
if (theElement.className == 'hdnvch') {
location.href = 'weeklycal.cfm?mo=#url.mo#&ye=#url.ye#&da=' +i;
}
else if (i == thismonth)
{
location.href = 'weeklycal.cfm?mo=#url.mo#&ye=#url.ye#&da=1';
}
}
}
</script>
</cfoutput>
I have made another function (wcal()) which identifies which cell the user has clicked on by checking the class should be "hdnvch" and accordingly uses that cell name as a parameter for where the link should go. If the user has not selected any cell, which means all cells have the class "hdnvc", I have tried to put in a clause (else if ) that if the loop reaches the last cell without encountering any cell with class "hdnvch", then go to a different link. The moment I add this clause, the function starts ignoring the first clause (if) and always goes to the link in the second clause (else if). If I take off the clause (else if), the link goes to the parameter of the selected cell, but then if no cell is selected, the link doesn't work.
I am sure I am making a very obvious error in coding. I have no experience in javascript and I made these functions reading through this forum.
I will be very grateful for any advise, pointers, suggestions, guidance. The two functions are listed below. Thx in advance. Please ignore the coldfusion parameters enclosed within # #. They work alright.
<cfoutput>
<script type="text/javascript">
function calchg(sel) {
for (var i=1; i<32; i++) {
var theElement = document.getElementById(i);
if (i == sel) {
theElement.className = 'hdnvch';
}
else {
theElement.className = 'hdnvc';
}
}
}
</script>
<script type="text/javascript">
var thismonth;
thismonth = #DaysInMonth(CreateDate(url.ye,url.mo,1))#;
function wcal() {
for (var i=1; i<=thismonth; i++) {
var theElement = document.getElementById(i);
if (theElement.className == 'hdnvch') {
location.href = 'weeklycal.cfm?mo=#url.mo#&ye=#url.ye#&da=' +i;
}
else if (i == thismonth)
{
location.href = 'weeklycal.cfm?mo=#url.mo#&ye=#url.ye#&da=1';
}
}
}
</script>
</cfoutput>