I'm translating an old asp site with include files into asp.net with a master page. One of the things I'm running into is the Object expected error for what looks fairly straight forward to me. The Javascript is in the head area. and the relevant parts
look like this;
<script type="text/javascript">
var bInMyBen = false;
var iDivLeft;
var iDivMenuTop;
var iDivSpeed = 35;
var iDivTop;
var iMenuSpeed = 25;
var iMenuTop = 76;
var iMyBenTop;
var iMyJobTop;
var iMyLesTop;
var iQLinkTop;
var DivTimerID;
var MyBenTimerID;
var MyJobTimerID;
var MyLesTimerID;
var QLinkTimerID;
var SSSTimerID;
var iSSSLeft;
var iSSSSpeed = 35;
var iSSSTop;
var EmpHeight;
var EmpWidth;
var ScnHeight = screen.height - 100;
var ScnWidth = screen.width - 20;
if (ScnHeight < 1200) {
EmpHeight = ScnHeight * .3;
}else{
EmpHeight = 350;
}
EmpWidth = EmpHeight * .5;
When I run in debug the SetMenus(); for the onload is highlighted as the source of the error. I'm a little confused as to if the body tag is the issue or if it is in the SetMenus function.
kraznodar
Contributor
3332 Points
881 Posts
Need help figuring out Microsoft JScript runtime error: Object expected
Aug 10, 2012 06:55 PM|LINK
I'm translating an old asp site with include files into asp.net with a master page. One of the things I'm running into is the Object expected error for what looks fairly straight forward to me. The Javascript is in the head area. and the relevant parts look like this;
<script type="text/javascript">
var bInMyBen = false;
var iDivLeft;
var iDivMenuTop;
var iDivSpeed = 35;
var iDivTop;
var iMenuSpeed = 25;
var iMenuTop = 76;
var iMyBenTop;
var iMyJobTop;
var iMyLesTop;
var iQLinkTop;
var DivTimerID;
var MyBenTimerID;
var MyJobTimerID;
var MyLesTimerID;
var QLinkTimerID;
var SSSTimerID;
var iSSSLeft;
var iSSSSpeed = 35;
var iSSSTop;
var EmpHeight;
var EmpWidth;
var ScnHeight = screen.height - 100;
var ScnWidth = screen.width - 20;
if (ScnHeight < 1200) {
EmpHeight = ScnHeight * .3;
}else{
EmpHeight = 350;
}
EmpWidth = EmpHeight * .5;
function SetMenus() {
//iDivMenuTop = iMenuTop + (document.all.spnQLink.clientHeight * .75);
iDivMenuTop = iMenuTop + 25;
document.all.spnDiv.style.left = 125;
iDivTop = iMenuTop - (document.all.spnDiv.clientHeight + 5);
document.all.spnDiv.style.top = iDivTop;
iSSSMenuTop = iMenuTop + 190;
document.all.spnSSS.style.left = 125;
iSSSTop = iMenuTop - (document.all.spnSSS.clientHeight + 5);
document.all.spnSSS.style.top = iSSSTop;
iMyBenTop = iMenuTop - (document.all.spnMyBen.clientHeight + 5);
document.all.spnMyBen.style.top = iMyBenTop;
iMyJobTop = iMenuTop - (document.all.spnMyJob.clientHeight + 5);
document.all.spnMyJob.style.top = iMyJobTop;
iMyLesTop = iMenuTop - (document.all.spnMyLes.clientHeight + 5);
document.all.spnMyLes.style.top = iMyLesTop;
iQLinkTop = iMenuTop - (document.all.spnQLink.clientHeight + 5);
document.all.spnQLink.style.top = iQLinkTop;
document.all.spnQLink.style.top = iMenuTop;
document.all.frmDiv.style.left = document.all.spnDiv.style.left;
document.all.frmDiv.style.top = document.all.spnDiv.style.top;
document.all.frmDiv.style.height = document.all.spnDiv.clientHeight;
document.all.frmDiv.style.width = document.all.spnDiv.clientWidth;
document.all.frmSSS.style.left = document.all.spnSSS.style.left;
document.all.frmSSS.style.top = document.all.spnSSS.style.top;
document.all.frmSSS.style.height = document.all.spnSSS.clientHeight;
document.all.frmSSS.style.width = document.all.spnSSS.clientWidth;
document.all.frmMyBen.style.left = document.all.spnMyBen.style.left;
document.all.frmMyBen.style.top = document.all.spnMyBen.style.top;
document.all.frmMyBen.style.height = document.all.spnMyBen.clientHeight;
document.all.frmMyBen.style.width = document.all.spnMyBen.clientWidth;
document.all.frmMyJob.style.left = document.all.spnMyJob.style.left;
document.all.frmMyJob.style.top = document.all.spnMyJob.style.top;
document.all.frmMyJob.style.height = document.all.spnMyJob.clientHeight;
document.all.frmMyJob.style.width = document.all.spnMyJob.clientWidth;
document.all.frmMyLes.style.left = document.all.spnMyLes.style.left;
document.all.frmMyLes.style.top = document.all.spnMyLes.style.top;
document.all.frmMyLes.style.height = document.all.spnMyLes.clientHeight;
document.all.frmMyLes.style.width = document.all.spnMyLes.clientWidth;
document.all.frmQLink.style.left = document.all.spnQLink.style.left;
document.all.frmQLink.style.top = document.all.spnQLink.style.top;
document.all.frmQLink.style.height = document.all.spnQLink.clientHeight;
document.all.frmQLink.style.width = document.all.spnQLink.clientWidth;
document.body.style.visibility = 'visible';
}
And the body tag looks like this;
<body style="margin-left:0; margin-top:0;" onload="SetMenus();" onresize="SetMenus();sizeContent();">
When I run in debug the SetMenus(); for the onload is highlighted as the source of the error. I'm a little confused as to if the body tag is the issue or if it is in the SetMenus function.
Any ideas or suggestions?
A1ien51
All-Star
29935 Points
5821 Posts
Re: Need help figuring out Microsoft JScript runtime error: Object expected
Aug 10, 2012 08:26 PM|LINK
document.all.spnQLink.clientHeight is BAD BAD CODE, you should never use document.all, that is depreecated IE only syntax. Also doing
document.all.frmQLink over and over again is bad practice. It requires multiple dom lookups.
Change the code to use document.getElementById() and store it into a variable.
var elem = document.getElementById("frmQLink"); elem.style.top = "100px"; elem.style.color = "#FF0000";Now do you know what line the error happens on? Debugger in IE8+ should take you right there.
Eric