Wrox Programmer Forums
|
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
 
Old January 24th, 2008, 02:12 PM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>&nbsp;</td>
    </tr>
</table>


 
Old January 24th, 2008, 02:19 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old January 24th, 2008, 03:05 PM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old January 24th, 2008, 03:26 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old January 24th, 2008, 04:48 PM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 = "&nbsp;";
        document.frm.counter.value = i; //avoid add row loop
       }
    }
 }
 
Old January 25th, 2008, 08:31 AM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe:

Thank you!
:)

 
Old January 25th, 2008, 08:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old January 25th, 2008, 09:26 AM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old January 25th, 2008, 09:56 AM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe:

The only thing that might be missing is the row #.
Who knows?

Onto next issue ...
LOL

 
Old January 25th, 2008, 11:50 AM
Authorized User
 
Join Date: Jan 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ...







Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Required Error JeffGirard Access 5 October 2nd, 2009 08:09 AM
Compile Error: Object required DeannaF829 Beginning VB 6 1 April 24th, 2007 07:12 AM
MSXML Object Required Error??? kevorkian Classic ASP Basics 1 January 5th, 2007 12:43 PM
Object required error ?? hman SQL Server ASP 11 June 21st, 2004 10:59 AM
error....Object required: '' sassenach Classic ASP Databases 2 August 4th, 2003 03:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.