Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 24th, 2008, 02:12 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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>


Reply With Quote
  #2 (permalink)  
Old January 24th, 2008, 02:19 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #3 (permalink)  
Old January 24th, 2008, 03:05 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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?
Reply With Quote
  #4 (permalink)  
Old January 24th, 2008, 03:26 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #5 (permalink)  
Old January 24th, 2008, 04:48 PM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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
       }
    }
 }
Reply With Quote
  #6 (permalink)  
Old January 25th, 2008, 08:31 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe:

Thank you!
:)

Reply With Quote
  #7 (permalink)  
Old January 25th, 2008, 08:44 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #8 (permalink)  
Old January 25th, 2008, 09:26 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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.

Reply With Quote
  #9 (permalink)  
Old January 25th, 2008, 09:56 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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

Reply With Quote
  #10 (permalink)  
Old January 25th, 2008, 11:50 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
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 ...


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.