PDA

View Full Version : Error: 'document.getElementById(...)' is null or not an object


sooner2k1
06-15-2007, 06:51 AM
Hi,

I recently had a programmer create a scrolling box that sums my product price, and now I am getting errors in IE.

When I asked the programmer to correct the issue, he claimed that the problem lies in the fact that earlier versions of IE do not know how to recognize layers.

However I have since downloaded 3 new versions of IE, and the errors do not go away.

Here is the page location: www.elypc.com/ccc_new1.php and www.elypc.com/ccc_new.php

Here is where I believe the issue lies.

"<script language="javascript">
<!--
var showImages="true";var showTotal="true";var showSubTotal="true";var showTaxes="false";var showBase="true";var showBuild="true";var showCommission="false";var showPriceDiffs="true";var showCurrentProducts="true";


var buildPrice="140";



var priceWithTax="false";var title="US Dollar";var symbol_left="$";var symbol_right="";var decimal_point=".";var thousands_point=",";var decimal_places="2";var currency_value="1.00000000";var tax_rate="17.5";var popupImageHeight="100%";var popupImageWidth="100";var textIncluded="Included In Price";var textMoreInfo="More Info";var textFree="<b>FREE!</b>";var textNone="<b>NONE!</b>";var useCommission="false";var baseProductPrice="0";var Computers = [['Case','ccc_part[86]'],['Power Supply','ccc_part[87]'],['Processor','ccc_part[88]'],['Motherboard','ccc_part[89]'],['Memory #1','ccc_part[90]'],['Memory #2','ccc_part[134]'],['Video Card #1','ccc_part[91]'],['Video Card #2 (SLI)','ccc_part[92]'],['Hard Drive','ccc_part[93]'],['Hard Drive #2 (Please Choose Raid 0 or 1)','ccc_part[130]'],['Optical Drive','ccc_part[94]'],['Sound','ccc_part[95]'],['Network','ccc_part[96]'],['Mouse','ccc_part[99]'],['Keyboard','ccc_part[100]'],['Operating System','ccc_part[101]'],['Monitor','ccc_part[102]'],['Extras','ccc_part[129]'],['Warranty','ccc_part[141]'],];

function myfunction() {
}

function form_reset(fname) {
fname.reset()
showimage_checkbox('ccc_part[86]', 'init');showimage_checkbox('ccc_part[87]', 'init');showimage_checkbox('ccc_part[88]', 'init');showimage_checkbox('ccc_part[89]', 'init');showimage_checkbox('ccc_part[90]', 'init');showimage_checkbox('ccc_part[134]', 'init');showimage_checkbox('ccc_part[91]', 'init');showimage_checkbox('ccc_part[92]', 'init');showimage_checkbox('ccc_part[93]', 'init');showimage_checkbox('ccc_part[130]', 'init');showimage_checkbox('ccc_part[94]', 'init');showimage_checkbox('ccc_part[95]', 'init');showimage_checkbox('ccc_part[96]', 'init');showimage_checkbox('ccc_part[99]', 'init');showimage_checkbox('ccc_part[100]', 'init');showimage_checkbox('ccc_part[101]', 'init');showimage_checkbox('ccc_part[102]', 'init');showimage_checkbox('ccc_part[129]', 'init');showimage_checkbox('ccc_part[141]', 'init'); update_total()
}
//-->
</script>"

AND

"<script>
if (!document.layers)
document.write('<div id="divStayTopRight" style="position:absolute">')

function submitform()
{
document.builds.submit();
}
</script>

<layer id="divStayTopRight">

<table border="1" width="120" cellspacing="0" cellpadding="0" background-color="lightgrey">
<tr>
<td width="100%" bgcolor="#0674BD">
<p align="center"><b><font size="4" color="#ECECEC">Summary</font></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#ECECEC">
<center><b>ElyPC Intel Gaming PC</b>
<img src="images//Blue%20Gaming%20PC%20Intel%20Logo.jpg" width="100" height="100" />
<font size="-1"><b>Total Price<br></b></font><b id="Total_Sidebar" style=" color:#0674BD; font-size:10pt; text-align:center;"><script>document.write(document.getElementById('Total_Top').innerHTML);</script>
</b>
<br><font size="-1"><b>Exp. Ship Date</b><br></font><font size="-1" color="#0674BD"><b>06-21-2007</b></font>
<img SRC="images/addtocart1.gif" name="sidebar_submit" onmouseover="document.images['sidebar_submit'].src='images/addtocart2.gif';" onmouseout="document.images['sidebar_submit'].src='images/addtocart1.gif';" onClick='javascript: submitform()' BORDER="0" height="30" ALT="Submit Form"><br><img TYPE="image" SRC="images/resetform2.gif" name="sidebar_reset" onmouseover="document.images['sidebar_reset'].src='images/resetform1.gif';" onmouseout="document.images['sidebar_reset'].src='images/resetform2.gif';" onClick='form_reset(document.builds)'BORDER="0" height="30" ALT="Submit Form"></center>
</tr>
</table>

</layer>


<script type="text/javascript">
var verticalpos="fromtop"

if (!document.layers)
document.write('</div>')

function JSFX_FloatTopDiv()
{
var startX = 0,
startY = 260;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.right=x;this.style.top=y;};
el.x = startX;
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopRight=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopRight()", 10);
}
ftlObj = ml("divStayTopRight");
stayTopRight();
}
JSFX_FloatTopDiv();
document.getElementById('sysdesc').innerHTML = build_table();
document.getElementById('Sidebar_Image').innerHTML = build_table();
</script>"


Is the programmer just not able to fix the problem, and is telling me that he fixed it, or is there a chance that this issue just wont go away.

Any info is appreciated.

_Aerospace_Eng_
06-15-2007, 07:22 AM
I'm going for what you said here
Is the programmer just not able to fix the problem, and is telling me that he fixed it
TBH it looks like he copy and pasted a preexisting script and doesn't know how it works. Change this
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
to this
var el=d.getElementById(id);

sooner2k1
06-15-2007, 07:50 AM
Hi,

I tried that, but it did not seem to make the error go away. Here is what I have now (with same error messages).

<script>
if (!document.layers)
document.write('<div id="divStayTopRight" style="position:absolute">')

function submitform()
{
document.builds.submit();
}
</script>

<layer id="divStayTopRight">

<table border="1" width="120" cellspacing="0" cellpadding="0" background-color="lightgrey">
<tr>
<td width="100%" bgcolor="#0674BD">
<p align="center"><b><font size="4" color="#ECECEC">Summary</font></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#ECECEC">
<center><b><? echo ($obfsb->fsb_name);?></b>
<img src="images//Blue%20Gaming%20PC%20Intel%20Logo.jpg" width="100" height="100" />
<font size="-1"><b>Total Price<br></b></font><b id="Total_Sidebar" style=" color:#0674BD; font-size:10pt; text-align:center;"><script>document.write(document.getElementById('Total_Top').innerHTML);</script>
</b>
<br><font size="-1"><b>Exp. Ship Date</b><br></font><font size="-1" color="#0674BD"><b><? echo ($next_year);?></b></font>
<img SRC="images/addtocart1.gif" name="sidebar_submit" onmouseover="document.images['sidebar_submit'].src='images/addtocart2.gif';" onmouseout="document.images['sidebar_submit'].src='images/addtocart1.gif';" onClick='javascript: submitform()' BORDER="0" height="30" ALT="Submit Form"><br><img TYPE="image" SRC="images/resetform2.gif" name="sidebar_reset" onmouseover="document.images['sidebar_reset'].src='images/resetform1.gif';" onmouseout="document.images['sidebar_reset'].src='images/resetform2.gif';" onClick='form_reset(document.builds)'BORDER="0" height="30" ALT="Submit Form"></center>
</tr>
</table>

</layer>


<script type="text/javascript">
var verticalpos="fromtop"

if (!document.layers)
document.write('</div>')

function JSFX_FloatTopDiv()
{
var startX = 0,
startY = 260;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById(id) ;
el.sP=function(x,y){this.style.right=x;this.style.top=y;};
el.x = startX;
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopRight=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopRight()", 10);
}
ftlObj = ml("divStayTopRight");
stayTopRight();
}
JSFX_FloatTopDiv();
document.getElementById('sysdesc').innerHTML = build_table();
document.getElementById('Sidebar_Image').innerHTML = build_table();
</script>