divs, innerHTML and unknown runtime errors

R

rwalrus

Getting an "unknown runtime error code 0" in IE6 on the last two lines
of the function below. Works fine in Firefox 1.5, I can't figure out
what IE is complaining about. Both "subtotal" and "totaldiv" are divs
with the respective ids, both contain only "$0" initially.

function updateprice(packageName) {
document.orderForm.Subpackage.value = packageName;
var tempsub =
getSelectedRadioValue(document.orderForm.subscription);
var sub1 = tempsub.split(":");
var suba = sub1[0];
var subb = sub1[1];
totalprice = document.orderForm.seats.value * suba;
shippingprice = document.orderForm.shipping.value
document.getElementById("total").value = (parseInt(totalprice) +
parseInt(shippingprice));
document.orderForm.subtotal.value = totalprice;
document.getElementById('subtotal').innerHTML = '$' + totalprice;
document.getElementById("totaldiv").innerHTML = "$" +
(parseInt(totalprice) + parseInt(shippingprice))
}

The named "subtotal" child of orderForm is getting set correctly, so
it's something about setting the innerHTML in the divs. Looked through
the groups/googled, most of what I found referenced altering table
structure, which I'm not doing.

Any thoughts?
 
M

marss

rwalrus said:
var subb = sub1[1];
totalprice = document.orderForm.seats.value * suba;

You multiply two string values. Convert them to integers or floats
before multiplication.
(parseInt, parseFloat)

totalprice = parseInt(document.orderForm.seats.value) * parseInt(suba);
 
M

marss

rwalrus said:
totalprice = document.orderForm.seats.value * suba;

You multiply two string values. You should convert it to desired type
with "parseInt" or "parseFloat" functions.
Eg.:
totalprice = parseInt(document.orderForm.seats.value) * parseInt(suba);

Maybe you problem is here.
 
R

RobG

marss said:
rwalrus said:
var subb = sub1[1];
totalprice = document.orderForm.seats.value * suba;


You multiply two string values. Convert them to integers or floats
before multiplication.
(parseInt, parseFloat)

That is unnecessary, strings are converted to numbers (if they can be)
as a part of the multiplication process. If they can't, the result is
NaN, which is not the error that the OP reported.

totalprice = parseInt(document.orderForm.seats.value) * parseInt(suba);

parseInt should never be used without a radix, particularly when
processing string input that may contain leading zeros.
 
R

RobG

UnaCoder said:
Switch to double quotes on referencing subtotal and the string, see if
that helps

It shouldn't. Double and single quotes are interchangeable, provided
they are nested correctly. There is no thing in the posted code to
indicate that they aren't (nested correctly).
 
R

RobG

rwalrus said:
Getting an "unknown runtime error code 0" in IE6 on the last two lines
of the function below. Works fine in Firefox 1.5, I can't figure out
what IE is complaining about. Both "subtotal" and "totaldiv" are divs
with the respective ids, both contain only "$0" initially.

You have a form element named 'subtotal' and a div with the same ID. IE
doesn't like that, change one of them.

[...]
 
V

VK

rwalrus said:
document.orderForm.subtotal.value = totalprice;
document.getElementById('subtotal').innerHTML = '$' + totalprice;

.... which suggests that you have a form element and a DIV named
"subtotal" (I guess the same with "total"). You cannot do that in IE,
because it implements a broken namespace schema.

Go through you page (and any others if needed) and make sure that *no
one* ID on the page repeats an ID *or* NAME of a form element. So say
if you have:
<input type="text" name="subtotal" id="subtotalID">
you cannot use neither "subtotal" nor "subtotalID" anywhere else: nor
for div's, nor for iframe's, nor for nothing.

Correct this and it will work (unless of course you have other errors
in your script :)
 
T

Thomas 'PointedEars' Lahn

marss said:
rwalrus said:
var subb = sub1[1];
totalprice = document.orderForm.seats.value * suba;

You multiply two string values. Convert them to integers or floats
before multiplication.
(parseInt, parseFloat)

As Rob said.

Furthermore, there is only one external numerical type in the corresponding
ECMAScript implementations as yet: `number', an IEEE-754 double-precision
floating-point number value, no matter its string representation (such as
with window.alert()). In those implementations, unsigned 32-bit Integers
are used internally only. parseInt() and parseFloat() do not convert a
string value to an integer value or a float value, respectively. Both
merely parse a string in a certain way and return the corresponding
`number' value.


PointedEars
 
R

rwalrus

VK said:
... which suggests that you have a form element and a DIV named
"subtotal" (I guess the same with "total"). You cannot do that in IE,
because it implements a broken namespace schema.

Go through you page (and any others if needed) and make sure that *no
one* ID on the page repeats an ID *or* NAME of a form element. So say
if you have:
<input type="text" name="subtotal" id="subtotalID">
you cannot use neither "subtotal" nor "subtotalID" anywhere else: nor
for div's, nor for iframe's, nor for nothing.

Correct this and it will work (unless of course you have other errors
in your script :)

That fixed it. Thanks for the help. Most of the underlying code and
markup I'm trying to maintain is not mine, and pretty hackwork, so a
lot of these bizzare errors keep cropping up. I appreciate the help.
 
V

VK

rwalrus said:
That fixed it. Thanks for the help. Most of the underlying code and
markup I'm trying to maintain is not mine, and pretty hackwork, so a
lot of these bizzare errors keep cropping up. I appreciate the help.

You are welcome. I'd just like to point out that the original code did
not contain any documented execution-prohibitive mistakes.

OK, I don't like "lazy syntacs" for forms
(document.orderForm.subtotal.value instead of
document.forms['orderForm'].elements['subtotal'].value). But this may
lead to a real mistake only in some particular circumstances - with
some "strange" form and elements names - and it was not a case here.

The real reason was in the brocken IE's namespace which is by design
and you are not responsible for. First of all, all HTML elements in IE
with ID's are being added to a special undocumented namespace between
global vars and Host Object. Secondly NAME's and ID's are being treated
equally and equally added to this space. Together it produces a real
mess. There is absolutely no reason for <input name="subtotal"> to have
any conflicts with <div id="subtotal">. And it doesn't anywhere: except
IE.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top