Dennis Martinez
Dennis Martinez

Reputation: 6512

JS Error in IE 8... "Object Required"

I am implementing pagination on a project currently in progress but I am getting an error with this piece of code in IE8:

var rows = document.getElementById(tableName).rows;

Here is the error:

Message: Object required

I am using this open source code for the pagination:

http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/

Now my question would be, is this a valid piece of code for ie 8? if not what could I substitute to obtain the same results of the given piece of code? (or how can i fix this error :P)

If more information is needed, I'll try my best to provide.

Upvotes: 0

Views: 3203

Answers (2)

Oyeme
Oyeme

Reputation: 11235

Better to use jquery for this. IF you use a jquery "if object is not found - no error will be returned"

Use it like this:

var table =  $('#tableName'); 

Upvotes: 0

nickf
nickf

Reputation: 546503

It looks like document.getElementById(tableName) is not finding the table which you're expecting, and so it returns null. null.rows is not valid, and so there's an error there.

I'd recommend splitting that line into two and checking that the element is found before continuing:

var table = document.getElementById(tableName),
    rows;
if (table) {
    rows = table.rows;
} else {
    alert("Couldn't find table with id: " + tableName);
}

Upvotes: 2

Related Questions