|
Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
January 24th, 2008, 02:12 PM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Object Required error
Gang:
Iâm having an âobject requiredâ yellow caution error with a function that was added to a legacy ASP page on an intranet.
Thereâs a DHTML menu that is hidden by a select form element. I tried the vendorâs solutions, but none worked.
That being said, I created a workaround that functions (e.g. no issues). Depending on mouse position, the select is moved up or down via a dummy table & row.
I tested all the functions, but itâs the âRemoveRowsâ function that creates the error. I isolated the error to one line (e.g. bolded).
My objective is to get the page working without any visible errors.
Any suggestionsâ¦
function FindXyCoords () //find mouse x y coords
{
var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY;
y = window.event.clientY;
// document.getElementById('divCoord').innerText = s; write coord
// <div id="divCoord"></div> o/p coord
if
(y < 150)
{
AddRows('WhatTbl');
}
else
{
RemoveRows('WhatTbl');
}
}
i = 0 //init counter
function AddRows (WhatTbl) // move select 3 rows down since overlaps nav mnu
{
if
(document.frm.counter.value < 3)
{
for
(i = 1; i < 4; i++) //already have empty row, so need 3 >
{
tblBody = document.getElementById(WhatTbl).tBodies[0];
newNode = tblBody.rows[0].cloneNode(true);
tblBody.appendChild(newNode);
document.frm.counter.value = i; //avoid add row loop
}
}
}
function RemoveRows (WhatTbl) // move select 3 rows up since overlaps nav mnu
{
tbl = document.getElementById(WhatTbl);
totalRows = tbl.rows.length;
if
(totalRows > 1) //can't delete 1st row
{
tbl.deleteRow(totalRows - 1); //totalRows 1 > than counter
document.frm.counter.value = 0; //reset so can add rows
}
}
<table border = 0 cellspacing = 0 cellpadding = 0 width = 0 id = "WhatTbl">
<tr>
<td> </td>
</tr>
</table>
|
January 24th, 2008, 02:19 PM
|
|
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If you have Visual Studio installed or the Script Editor that comes with Office then you can uncheck the "Disable script debugging (Internet Explorer)" option in Tools > Internet options > Advanced. You can then load the page and then step through and see exactly where the error occurs.
I find that a lot of these errors are caused by objects or functions being referenced before they are available. Often the code is tested by people who are running a local web server where slow downloads and rendering don't occur, unlike the real world.
--
Joe ( Microsoft MVP - XML)
|
January 24th, 2008, 03:05 PM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
Good suggestion!
In 'RemoveRows' function, tbl was 'null' while totalRows was 'object required'.
When holding mouse over tbl.rows.length, the length = 1. This is correct since dummy table/row never deleted.
Am I referencing objects incorrectly?
|
January 24th, 2008, 03:26 PM
|
|
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Strange, if tbl is null then tbl.rows will be null too. One explanation I can see is that something is amiss because you declare tbl as a global variable. Try using var tbl = . You could also use the correct functions for adding rows, insertRow and insertCell rather than cloneNode and appendChild.
--
Joe ( Microsoft MVP - XML)
|
January 24th, 2008, 04:48 PM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
var had no effect, nor did insertRow, insertCell
While testing, I think that the mouse position is causing the error.
If below the y coord, the error occurs, else another error.
Both of the items in question exist, so it's just a reference error as opposed to a functional one.
I'll think I'll leave it as is since the nav mnu issue is fixed.
Rewrote AddRows f(x), makes > sense
i = 0; //init counter
function AddRows (WhatTbl) // move select 3 rows down since overlaps nav mnu
{
if
(document.frm.counter.value < 3)
{
for
(i = 1; i < 4; i++) //already have empty row, so need 3 >
{
x = document.getElementById('WhatTbl').insertRow(0);
y = x.insertCell(0);
y.innerHTML = " ";
document.frm.counter.value = i; //avoid add row loop
}
}
}
|
January 25th, 2008, 08:31 AM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
Thank you!
:)
|
January 25th, 2008, 08:44 AM
|
|
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by voyeur
Joe:
Thank you!
:)
|
You're welcome, did it finally work?
I get the feeling that there's something we're both missing but testing another's aspx/JavaScript app via a forum is not easy :)
--
Joe ( Microsoft MVP - XML)
|
January 25th, 2008, 09:26 AM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
I went back to test it this morning. It didn't have any issues the first two times I visited the page. The third time, the error came back.
Everything works peachy. It's the RemoveRows function which causes the 'tbl.rows.length' & global counter 'object required' errors.
I'll play with it some more. It's only going on the intranet, & the legacy navigation menu issue is resolved.
|
January 25th, 2008, 09:56 AM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
The only thing that might be missing is the row #.
Who knows?
Onto next issue ...
LOL
|
January 25th, 2008, 11:50 AM
|
Authorized User
|
|
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe:
Added same code to two other pages ...
Original page has issue everytime since pdfs presented in another frame.
Other two pages intermittent ...
Must be something to do with legacy pages ...
Hope it's warmer where you are ...
|
|
|