473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getting Error: Object expected

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
8 4659
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rick | last post by:
I wrote the following code as part of a page where users can reorder a list of items by highlighting an item in a list box and clicking an "up" or "down" button to move the items around. The code...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
2
by: khalaskapil | last post by:
i m getting Object Expected error, i m using master page & i m call javascript function in child age: this is my child page where i m calling javascript functionNewCal(), <div> ...
6
by: =?Utf-8?B?dGhsMTAwMA==?= | last post by:
Hi NG, i need to list the logonHours for a specific user. I'm trying to convert code from vbscript (is working) to vb.net, but the vb.net code does not work. Here are the code listings: 1:...
1
by: JOJO123 | last post by:
I got here in search of an answer to this Javascrpt question. I upgraded jave on XP Ie 7, acrobat 5.1 and suddenly can't open any pdf files on web sites using IE. I see u guys all say, this is a...
6
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. ...
1
by: Rahul | last post by:
I am getting following error: 1) For a xml file "Request.xml" we created a schema "Request.xsd". 2) With the help of xsd.exe we got the C# file Request.cs. 3) We tried to send the object of...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.