getting Error: Object expected

I

ipy2006

In my HTML I have,
<input type="button" class="cartonsumkey" value="Sum Cartons"
onclick="sumup(this);" />

In an external file that is called in Head area, I have,

function sumup( o ) {

var totoalCartons = 0;
var row = document.getElementById( 'oceanDeliveries' ).rows;
var i = row.length - 1;
var lastrow = row;

while(i--) {
totalCartons += parseInt( row.cells[8].innerText ) || 0;
}

if( lastrow.cells[8] ) {
lastrow.cells[8].firstChild.nodeValue = totalCartons;
}

o.disabled = true;
}

I am getting Error: Object expected.

Please help!

Thanks,
Yasaswi
 
D

Darko

In my HTML I have,
<input type="button" class="cartonsumkey" value="Sum Cartons"
onclick="sumup(this);" />

In an external file that is called in Head area, I have,

function sumup( o ) {

var totoalCartons = 0;
var row = document.getElementById( 'oceanDeliveries' ).rows;
var i = row.length - 1;
var lastrow = row;

while(i--) {
totalCartons += parseInt( row.cells[8].innerText ) || 0;
}

if( lastrow.cells[8] ) {
lastrow.cells[8].firstChild.nodeValue = totalCartons;
}

o.disabled = true;

}

I am getting Error: Object expected.

Please help!

Thanks,
Yasaswi


Is it possible that you simply have a syntax error, in the first line
of the function, where you wrote totOal instead of total? Try also not
passing the "this" object to the function, because it's automatically
available in the function if it's an event handler. That is, don't
pass "this" in the function call, don't declare "o" as function
argument, and use "this" in the function directly instead of "o". Use
firefox, too, so it can tell you in which line the error happens
(hint: use Error console in the Tools menu of Firefox).
 
R

RobG

In my HTML I have,
<input type="button" class="cartonsumkey" value="Sum Cartons"
onclick="sumup(this);" />

In an external file that is called in Head area, I have,

function sumup( o ) {

var totoalCartons = 0;

Did you mean: totalCartons ?
var row = document.getElementById( 'oceanDeliveries' ).rows;
var i = row.length - 1;
var lastrow = row;

while(i--) {


Since i is already the number of rows, this will skip the last row
(which I guess you want it to do).
totalCartons += parseInt( row.cells[8].innerText ) || 0;


innerText is an IE proprietary property that is not available in some
browsers, the W3C equivalent is textContent. You might consider using
the cell's firstChild.data or innerHTML property.

var cell = row.cells[8];
totalCartons += (cell.firstChild && +cell.firstChild.data);

or

totalCartons += +row.cells[8].innerHTML;

}

if( lastrow.cells[8] ) {
lastrow.cells[8].firstChild.nodeValue = totalCartons;
}

o.disabled = true;

What do you expect o is? What is it actually? Use an alert placed
before this line to find out:

alert( typeof o + '\n' + o.tagName);
}

I am getting Error: Object expected.

At which line?
 
I

ipy2006

In my HTML I have,
<input type="button" class="cartonsumkey" value="Sum Cartons"
onclick="sumup(this);" />
In an external file that is called in Head area, I have,
function sumup( o ) {
var totoalCartons = 0;

Did you mean: totalCartons ?
var row = document.getElementById( 'oceanDeliveries' ).rows;
var i = row.length - 1;
var lastrow = row;

while(i--) {

Since i is already the number of rows, this will skip the last row
(which I guess you want it to do).
totalCartons += parseInt( row.cells[8].innerText ) || 0;


innerText is an IE proprietary property that is not available in some
browsers, the W3C equivalent is textContent. You might consider using
the cell's firstChild.data or innerHTML property.

var cell = row.cells[8];
totalCartons += (cell.firstChild && +cell.firstChild.data);

or

totalCartons += +row.cells[8].innerHTML;
if( lastrow.cells[8] ) {
lastrow.cells[8].firstChild.nodeValue = totalCartons;
}
o.disabled = true;

What do you expect o is? What is it actually? Use an alert placed
before this line to find out:

alert( typeof o + '\n' + o.tagName);


I am getting Error: Object expected.

At which line?



Thank you Rob and Darko. The totalCartons typo was the problem.
Thanks a lot.
Yip
 
R

RobG

RobG wrote:

totalCartons += (cell.firstChild && +cell.firstChild.data);

I don't get this, Rob, surely the rh expression is Boolean, no?

No.

It is a shortcut way of checking that cell has a firstChild property
that doesn't evaluate to false (i.e. since it's a DOM object, that it
has a firstChild) before attempting to access one of cell.firstChild's
properties (and then converting it to a number).

The && operator is also called the "guard" operator. In an expression
like:

a && b && c

The expressions are evaluated from left to right until either the
result of one of them evaluates to false or there are no more
statements. The value of the last statement evaluated is returned, so
either the first that evaluates to false or the last one.

The "+" operator is used as a unary operator to convert the string
result of cell.firstChild.data to a number, hence:

cell.firstChild.data ==> String
+cell.firstChild.data ==> Number

it is short and faster than the (more or less) eqivalent:

parseInt(cell.firstChild.data, 10)

or

Number(cell.firstChild.data)
 
R

Richard Cornford

Michael said:
RobG wrote:

totalCartons += (cell.firstChild && +cell.firstChild.data);

I don't get this, Rob, surely the rh expression is Boolean, no?

With a logical expression in javascript the values of the sub-expressions
are type-converted to boolean in order to determine the result of the
whole expression (up to the point where the result can be certain (so in
this expression only the - cell.firstChild - is type converted to
boolean)) but the value of the whole expression is the value of the
significant sub-expression (not the type-converted to boolean equivalent
of that value).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top