By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

getting Error: Object expected

P: n/a
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[i];

while(i--) {
totalCartons += parseInt( row[i].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

Feb 28 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Feb 28, 10:52 pm, "ipy2006" <ipyasa...@gmail.comwrote:
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[i];

while(i--) {
totalCartons += parseInt( row[i].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).

Feb 28 '07 #2

P: n/a
On Mar 1, 7:52 am, "ipy2006" <ipyasa...@gmail.comwrote:
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[i];

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[i].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[i].cells[8];
totalCartons += (cell.firstChild && +cell.firstChild.data);

or

totalCartons += +row[i].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?

--
Rob

Feb 28 '07 #3

P: n/a
On Feb 28, 6:38 pm, "RobG" <r...@iinet.net.auwrote:
On Mar 1, 7:52 am, "ipy2006" <ipyasa...@gmail.comwrote:
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[i];
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[i].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[i].cells[8];
totalCartons += (cell.firstChild && +cell.firstChild.data);

or

totalCartons += +row[i].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?

--
Rob

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

Mar 1 '07 #4

P: n/a
ipy2006 wrote:

[snip]
>
Thank you Rob and Darko. The totalCartons typo was the problem.
Thanks a lot.
Yip
No, that is not your own problem, read Rob's post carefully.
Mick
Mar 4 '07 #5

P: n/a
RobG wrote:
totalCartons += (cell.firstChild && +cell.firstChild.data);

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

Mick
Mar 4 '07 #6

P: n/a
On Mar 4, 12:30 pm, Michael White <m...@mickweb.comwrote:
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)
--
Rob

Mar 4 '07 #7

P: n/a
Michael White wrote:
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.

Mar 4 '07 #8

P: n/a
Richard Cornford wrote:
Michael White wrote:
>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).
Thanks Rob and Richard.
Mick
Mar 6 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.