/    Sign up×
Community /Pin to ProfileBookmark

Hi everyone,

I am new to this forum kindly help me to find the bug in my calculator script. This script works only on IE 5.5 and above. The script works perfectly when you keep on clicking previous month or previous year or next month and next year button, the browse displays an error message and gets closed automaticly. I dont know where the bug is, my script contain two files calc.js and calc.html. i am also pasting the script also, kindly some on help me.

—— Begining of calc.js ———–

[B]var xrow = 0;
var xcol = 0;
var today = new Date();
var date = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var ydate = today.getDate();
var ymonth = today.getMonth();
var yyear = today.getFullYear();

var frm_year = 1901;
var to_year = 2999;
var max_year = year;
var months = [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”];
var days = [“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”];
var retfld = null;
var retfrm = null;
var cal = null;
function openCalc(row,col)
{
xrow = row;
xcol = col;
cal = null;
openCalc.prototype.cCalc = createCalc;
openCalc.prototype.oCalc = closeCalc;
}

function createCalc()
{
window.document.body.insertAdjacentHTML(“beforeEnd”, “<div id=’xcalc’ style=’position:absolute;border:2 solid’></div>”);
this.cal = window.document.getElementById(‘xcalc’);
this.cal.style.zIndex = 1;
this.cal.style.top = xrow;
this.cal.style.left = xcol;
this.cal.style.width = 300;
this.cal.style.height = 250;
this.cal.style.backgroundColor = “#CCCCFF”;
this.cal.style.visibility = ‘visible’;
genTable();
}

function closeCalc()
{
this.cal = window.document.getElementById(‘xcalc’);
this.cal.style.visibility = ‘hidden’;
}

function genTable()
{
this.cal = window.document.getElementById(‘xcalc’);
var str = “<center><table width=’100%’ border=’0′ cellspacing=’0′ cellpading=’0′><form name=’calcform’ id=’calfrm’>”+
“<tr><td align=’center’ colspan=’6′><b>Calendar</b><hr></td></tr>”+
“<tr><td width=’0%’ align=’center’><input type=’button’ name=’preyr’ id=’preyr’ value='<<‘ onClick=’selPyear()’></td>”+
” <td width=’0%’ align=’center’><input type=’button’ name=’premo’ id=’premo’ value='<‘ onClick=’selPmonth()’></td>”+
” <td width=’0%’ align=’center’><select name=’sel_month’ id=’sel_month’ onChange=’selMonth()’>”;
for(i=0; i<months.length; i++)
{
if(i == ymonth)
str+= “<option value='” + i + “‘ selected>”+months[i]+”</option>”;
else
str+= “<option value='” + i + “‘>”+months[i]+”</option>”;

}
str+=”</select></td>”+
” <td width=’0%’ align=’center’><select name=’sel_year’ onChange=’selYear()’>”;
for(i=frm_year; i<=max_year; i++)
{
if(i == yyear)
str+=”<option value='”+i+”‘ selected>”+i+”</option>”;
else
str+=”<option value='”+i+”‘>”+i+”</option>”;
}
str+=”</select></td>”+
” <td width=’0%’ align=’center’><input type=’button’ name=’nxtyr’ value=’>’ onClick=’selNmonth()’></td>”+
” <td width=’0%’ align=’center’><input type=’button’ name=’nxtmo’ value=’>>’ onClick=’selNyear()’></td></tr>”+

“<tr><td width=’0%’ colspan=’6′><hr></td></tr></table>”;
str+=”<table border=’0′ cellspacing=’0′ cellpading=’0′ width=’100%’>”+
“<tr><td width=’14%’ align=’center’><b>Sun</b></td>”+
” <td width=’14%’ align=’center’><b>Mon</b></td>”+
” <td width=’14%’ align=’center’><b>Tue</b></td>”+
” <td width=’15%’ align=’center’><b>Wed</b></td>”+
” <td width=’14%’ align=’center’><b>Thu</b></td>”+
” <td width=’15%’ align=’center’><b>Fri</b></td>”+
” <td width=’14%’ align=’center’><b>Sat</b></td><tr>”;

var day_id=0;
var date_id=1;
now = new Date(yyear,ymonth,date_id);
cmonth = now.getMonth();

while (ymonth == cmonth)
{

if(day_id > 6)
{
day_id = 0;
str+=”</tr><tr>”;
}

if(day_id != now.getDay())
{
str+=”<td align=’center’>&nbsp;</td>”;
}
else if(day_id == now.getDay())
{
if(now.getDate() > 9)
str+=”<td align=’center’><input name=’datefld’ type=’button’ value=’ “+now.getDate()+” ‘ onClick=’selDate()’></td>”;
else
str+=”<td align=’center’><input name=’datefld’ type=’button’ value=’ 0″+now.getDate()+” ‘ onClick=’selDate()’></td>”;

// if(now.getDate() == xdate)
// str+=”<td align=’center’><b>”+now.getDate()+”</b></td>”;
// else
// str+=”<td align=’center’>”+now.getDate()+”</td>”;

date_id++;
}
day_id++;
now = new Date(yyear,ymonth,date_id);
cmonth = now.getMonth();

}
str+=”</form></table></center>”;
this.cal.innerHTML=str;
return true;
}

function selMonth()
{
ymonth = document.calcform.sel_month.value;
this.genTable();
}

function selYear()
{
yyear = document.calcform.sel_year.value;
this.genTable();
}

function selPyear()
{
if(yyear != frm_year)
yyear–;

this.genTable();

}

function selPmonth()
{
ymonth–;

if(ymonth < 0)
{
if(yyear != frm_year)
yyear–;

ymonth=11;
}

this.genTable();

}

function selNyear()
{
if(yyear != max_year)
yyear++;

this.genTable();

}

function selNmonth()
{
ymonth++;

if(ymonth > 11)
{
if(yyear != max_year)
yyear++;

ymonth=1;
}

this.genTable();

}

function selDate(x)
{
alert(‘a’); // = ‘hi’;

}[/B]

———- end of calc.js ———

——— begining of calc.html ——–

[B]<html>
<body>
<head>
</head>
<script language=”javascript” src=”calc.js”></script>
<script language=”javascript” src=”select.js”></script>

<form name=’mainform’>
<input type=”text” name=”datefield”> <a href=”javascript:setCalc()”>Calender</a> <a href=”javascript:callDate()”>ICICI BANK</a>
</form>
<script language=”javascript”>
{
function setCalc()
{
qcal = new openCalc(100,100);
qcal.cCalc();
}
}
</script>
</body>

</html>[/B]
——— end of calc.html ———–

i have also attached the image of the error message.

thanks in advance

bye
saravana kumar

[upl-file uuid=111a111d-86ab-4712-909a-d107f7db8f92 size=30kB]error.JPG[/upl-file]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterJun 15.2005 — If you ZIP all of this, I'll give it a shot.
Copy linkTweet thisAlerts:
@rsk1239authorJun 16.2005 — ok, here is the calc.zip. It contains calc.js and calc.html kindly check it and spot the bug for me.

thankyou

[upl-file uuid=f8367208-8c71-4ef2-b530-439f33f54bd1 size=2kB]calc.zip[/upl-file]
×

Success!

Help @rsk1239 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...