PDA

View Full Version : Unescapable errors


Vlaad
09-03-2003, 01:51 AM
Hello,

I've built a javascript file, and the javascript therein seems, to me, quite simple and non-erroneous. However, using any browser, I get the "Error: document.getElementById(element) has no properties
Source File: http://localhost/res/js/scripts.js
Line: 7" error.

This is most upsetting, as the file seemed to be working just fine yesterday, and noone's touched it since.

Any help, preferably the swift variety, would be greatly appreciated!!!

Cheers in advance!!!

<!--

// Globals
var menuElements = new Array();


function hideElement(element)
{
document.getElementById(element).style.display = "none";
}


function unhideElement(element)
{
document.getElementById(element).style.display = "block";
}


function createCollapsibleElement(newelement)
{
menuElements.push(newelement);
hideElement(newelement);
}


function useCollapsibleElement(menuItemFocus)
{
// Step 1. Check if the (elements != menuItemFocus) in menuElements are visible, set style.display = none.
var counter = 0;

// Step 2. If the menuItemFocus has style=display = none, then open the subMenu, or else close it.
if (document.getElementById(menuItemFocus).style.display != "none")
{
hideElement(menuItemFocus);
document.getElementById(menuItemFocus + "Image").src = "res/img/body/main/widgets/tree/plus.gif";
}
else
{
unhideElement(menuItemFocus);
document.getElementById(menuItemFocus + "Image").src = "res/img/body/main/widgets/tree/minus.gif";
}
}


function MM_swapImgRestore()
{
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->

Vincent Puglia
09-03-2003, 02:01 AM
Hi,

The error message usually means that the 'element' is either ill-defined, created after (instead of before) the function is called, and/or passed incorrectly (spelling typo). At any rate, can't really help without the element's HTML and the function's call

Also, what is line 7 in the *.js file?

Vinny

Vlaad
09-03-2003, 02:12 AM
This is the entire source for the page. I actually was referencing the javascript in an external file, but for simplicity's sake I've copied all code into this post.

Please ignore the ASP - nothing wrong there.

The error is :
Error: document.getElementById(element) has no properties
Source File: http://localhost/main.asp
Line: 17


<%@ Language="VBScript" %>

<% Response.Buffer = True

DIm articleTotal
articleTotal = 0

Dim connectionString
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Inetpub\wwwroot\res\db\www.mdb;" & _
"User Id=Guest;" & _
"Persist Security Info=True;" & _
"Jet OLEDB:System Database=c:\Inetpub\wwwroot\res\db\www.mdw;" & _
"Jet OLEDB:Database Password=;"
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>TE Australia</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="res/css/main.css" rel="stylesheet" type="text/css">
<script language="Javascript">
<!--
// Globals
var menuElements = new Array();


function hideElement(element)
{
document.getElementById(element).style.display = "none";
}


function unhideElement(element)
{
document.getElementById(element).style.display = "block";
}


function createCollapsibleElement(newelement)
{
menuElements.push(newelement);
hideElement(newelement);
}


function useCollapsibleElement(menuItemFocus)
{
// Step 1. Check if the (elements != menuItemFocus) in menuElements are visible, set style.display = none.
var counter = 0;

// Step 2. If the menuItemFocus has style=display = none, then open the subMenu, or else close it.
if (document.getElementById(menuItemFocus).style.display != "none")
{
hideElement(menuItemFocus);
document.getElementById(menuItemFocus + "Image").src = "res/img/body/main/widgets/tree/plus.gif";
}
else
{
unhideElement(menuItemFocus);
document.getElementById(menuItemFocus + "Image").src = "res/img/body/main/widgets/tree/minus.gif";
}
}


function MM_swapImgRestore()
{
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->
</script>
</head>

<body>
<table cellpadding="10"><tr>
<td valign="top" align="left" width="100%" rowspan="2">
<h1>Latest News</h1>
<% Dim newsQuery, newsQueryCounter, newsFeaturesRows, newsFeaturesCols, newsSpecsRows, newsSpecsCols, rowCounter, colCounter
Set newsQuery = Server.CreateObject("ADODB.Recordset")
newsQuery.ActiveConnection = connectionString
newsQuery.Source = "SELECT * FROM tableNews" ' Global select
newsQuery.Open
newsQueryCounter = 0
rowCounter = 0
colCounter = 0
While Not newsQuery.EOF
%>
<table border="0" cellpadding="0" cellspacing="0" class="articleBlock" width="100%">
<tr>
<td valign="bottom" height="30"><a href="javascript: useCollapsibleElement('article<%= newsQueryCounter %>');"><img src="res/img/body/main/widgets/tree/plus.gif" width="9" height="30" border="0" id="article<%= newsQueryCounter %>Image"></a></td>
<td class="title">
<img src="<%= newsQuery.Fields.Item("Logo") %>" alt="TE Australia supplier logo" align="right" class="logo">
<a href="javascript: useCollapsibleElement('article<%= newsQueryCounter %>');"><%= newsQuery.Fields.Item("Title") %></a>
<span class="date">:: <%= MonthName(Split(newsQuery.Fields.Item("ReleaseDate"),"/")(1)) & " " & Split(newsQuery.Fields.Item("ReleaseDate"),"/")(2) %></span>
</td>
</tr>
<tr>
<td class="articleLeftSpan"><img src="res/img/transpacer.gif"></td>
<td class="articleBody">
<div id="article<%= newsQueryCounter %>">
<span class="blurb"><%= newsQuery.Fields.Item("Brief") %></span>
<%= newsQuery.Fields.Item("BodyHTML") %>
<% If newsQuery.Fields.Item("Features") Then
%>
<p class="subtitle">Features</p>
<% If newsQuery.Fields.Item("FeaturesBrief") <> "" Then
%>
<p><%= newsQuery.Fields.Item("FeaturesBrief") %></p>
<% End If
%>
<% If newsQuery.Fields.Item("Features") = 1 Then
newsFeaturesCols = UBound(Split(newsQuery.Fields.Item("FeaturesTableHeader"),"|"))
newsFeaturesRows = UBound(Split(newsQuery.Fields.Item("FeaturesTableHeader"),"|"))/UBound(Split(newsQuery.Fields.Item("FeaturesTableData"),"|"))
colCounter = 0
rowCounter = 0
%>
<table cellpadding="2" cellspacing="2" class="dataTable">
<tr>
<% While colCounter <= newsSpecsCols
Response.Write("<th>" & Split(newsQuery.Fields.Item("FeaturesTableHeader"),"|")(colCounter) & "</th>")
colCounter = colCounter + 1
Wend
%>
</tr>
<% While rowCounter < newsSpecsRows
colCounter = 0
%>
<tr>
<% While colCounter <= newsSpecsCols
Response.Write("<td>" & Split(newsQuery.Fields.Item("FeaturesTableData"),"|")(colCounter) & "</th>")
colCounter = colCounter + 1
Wend
%>
</tr>
<% rowCounter = rowCounter + 1
Wend
%>
</table>
<% Elseif newsQuery.Fields.Item("FeaturesTableAlignment") = 2 Then
newsFeaturesCols = UBound(Split(newsQuery.Fields.Item("FeaturesTableHeader"),"|"))
colCounter = 0
rowCounter = 0
%>
<table cellpadding="2" cellspacing="2" class="dataTable">
<% While rowCounter < newsFeaturesCols
Response.Write("<tr>")
Response.Write("<th>" & Split(newsQuery.Fields.Item("FeaturesTableHeader"),"|")(rowCounter) & "</th>")
Response.Write("<td>" & Split(newsQuery.Fields.Item("FeaturesTableData"),"|")(rowCounter) & "</td>")
Response.Write("</tr>")
rowCounter = rowCounter + 1
Wend
%>
</table>
<%
Else
newsFeaturesRows = 0
newsFeaturesCols = 0
End If
End If
If newsQuery.Fields.Item("FeaturesFootnotes") <> "" Then
%>
<p><%= newsQuery.Fields.Item("FeaturesFootnotes") %></p>
<% End If
%>
<% If newsQuery.Fields.Item("Specifications") Then
%>
<p class="subtitle">Specifications</p>
<% If newsQuery.Fields.Item("SpecificationsBrief") <> "" Then
%>
<p><%= newsQuery.Fields.Item("SpecificationsBrief") %></p>
<% End If
If newsQuery.Fields.Item("SpecificationsTableAlignment") = 1 Then
newsSpecsCols = UBound(Split(newsQuery.Fields.Item("SpecificationsTableHeader"),"|"))
newsSpecsRows = UBound(Split(newsQuery.Fields.Item("SpecificationsTableHeader"),"|"))/UBound(Split(newsQuery.Fields.Item("SpecificationsTableData"),"|"))
colCounter = 0
rowCounter = 0
%>
<table cellpadding="2" cellspacing="2" class="dataTable">
<tr>
<% While colCounter <= newsSpecsCols
Response.Write("<th>" & Split(newsQuery.Fields.Item("SpecificationsTableHeader"),"|")(colCounter) & "</th>")
colCounter = colCounter + 1
Wend
%>
</tr>
<% While rowCounter < newsSpecsRows
colCounter = 0
%>
<tr>
<% While colCounter <= newsSpecsCols
Response.Write("<td>" & Split(newsQuery.Fields.Item("SpecificationsTableData"),"|")(colCounter) & "</th>")
colCounter = colCounter + 1
Wend
%>
</tr>
<% rowCounter = rowCounter + 1
Wend
%>
</table>
<% Elseif newsQuery.Fields.Item("SpecificationsTableAlignment") = 2 Then
newsFeaturesCols = UBound(Split(newsQuery.Fields.Item("SpecificationsTableHeader"),"|"))
colCounter = 0
rowCounter = 0
%>
<table cellpadding="2" cellspacing="2" class="dataTable">
<% While rowCounter < newsFeaturesCols
Response.Write("<tr>")
Response.Write("<th>" & Split(newsQuery.Fields.Item("SpecificationsTableHeader"),"|")(rowCounter) & "</th>")
Response.Write("<td>" & Split(newsQuery.Fields.Item("SpecificationsTableData"),"|")(rowCounter) & "</td>")
Response.Write("</tr>")
rowCounter = rowCounter + 1
Wend
%>
</table>
<% Else
newsFeaturesRows = 0
newsFeaturesCols = 0
End If
%>
<p><%= newsQuery.Fields.Item("SpecificationsFootnotes") %></p>
<% End If

rowCounter = 0
colCounter = 0
%>
<% If newsQuery.Fields.Item("Datasheet") = True Then
%>
<p class="subtitle">Datasheet</p>
<%= newsQuery.Fields.Item("DatasheetBrief") %>
<p>The datasheet for this product is available for download: <a href="<%= newsQuery.Fields.Item("DatasheetLink") %>">click
here</a> to download.</p>
<% End If
%>
<% If newsQuery.Fields.Item("Background") = True Then
%>
<p class="subtitle">Background</p>
<p><%= newsQuery.Fields.Item("BackgroundBrief") %></p>
<p><%= newsQuery.Fields.Item("BackgroundFootnotes") %></p>
<% End If
%>
<p>For further information, including samples, pricing, data sheets,
etc., please <a href="/contactus.htm">contact TE Australia</a>.</p>
</div>
</td>
</tr>
<tr>
<td valign="top" class="articleLeftSpan"><img src="res/img/body/main/widgets/tree/corner.gif"></td>
<td class="articleFooter"><img src="res/img/transpacer.gif" width="9" height="3"></td>
</tr>
</table>
<br />

<% newsQuery.moveNext
newsQueryCounter = newsQueryCounter + 1
Wend
newsQuery.Close
%>
</td><td valign="top" align="right">
<form action="search.asp">
<table class="search" width="100%">
<tr>
<th colspan="2"><img src="res/img/body/main/widgets/help.gif" align="right" alt="Click for search tips" title="Search tips">Search TE Australia Online</th>
<tr>
<td class="element">Scope: </td>
<td><select name="scope" id="scope" class="input">
<option value="all">All</option>
<option value="news">News Articles</option>
<option value="stock">Discounted Stock</option>
<option value="datasheets">Datasheets</option>
<option value="promos">Promotions</option>
</select></td>
</tr>
<tr>
<td class="element">Keywords: </td>
<td><input name="keywords" type="text" id="keywords" class="input">
<label>
<input type="radio" name="matchtype" value="all">
All</label>
<label>
<input type="radio" name="matchtype" value="exact">
Exact match</label>
</td>
</tr>
<tr>
<td class="element">Supplier: </td>
<td><select name="supplier" id="supplier" class="input">
<option value="toshiba">Toshiba</option>
<option value="epson">EPSON</option>
<option value="protek">Protek Devices</option>
<option value="orient">Orient Microwave</option>
<option value="onsemi">ON Semiconductor</option>
<option value="eic">EiC</option>
<option value="pulse">Pulse Engineering</option>
<option value="npc">NPC</option>
<option value="semelab">Semelab</option>
<option value="semefab">Semefab</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input type="submit" name="Submit" value="Search" class="button">
</div></td>
</tr>
</table>
</form>
<table class="supplier" width="100%">
<tr>
<th colspan="2">Our Suppliers</th>
<tr>
<td class="list"><img src="res/img/logos/min/group_2cols.gif">
</td>
</tr>
</table>
</td></tr></table>

</body>
</html>


<script language="Javascript">
var counter = 0;
for (counter = 0; counter <= <%= newsQueryCounter %>; counter++)
{ createCollapsibleElement('article'+counter); }
</script>

glenngv
09-03-2003, 08:46 AM
It seems that the id passed is existing. Not sure though.

What browser are you using? Is it Netscape 4? It seems that the "__ has no properties" error is a NS-type error message.

FYI, document.getElementById is supported in IE5+ and NS6+

But if my assumption is wrong, view the generated HTML source by clicking View-Source in the menu. Look for the string "javascript: useCollapsibleElement" and then search for the id passed in that function to see if it really exists or not. Take note that it must exist only ONCE to be able to make the function work.