473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Works in firefox but not internet explorer

alexphd
19
This code works in firefox perfectly, but in Internet Explorer it does not calculate the total correctly. Anybody know why?



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en" dir="ltr">
<head>
<title>Order form</title>

<style type="text/css">
@media screen {
body {
font: 100% sans-serif;
}
h1 {
font: 130% normal sans-serif;
text-align: center;
}
fieldset {
border-style: none;
margin: 0 0 1em;
padding: 0.5ex;
}
label {
display: block;
margin-left: 1em;
width: 12em;
}
legend {
font-weight: bold;
margin: 0;
padding: 0;
}
#order {
position: relative;
}
#total {
display: block;
margin-left: auto;
margin-right: auto;
width: 6em;
}
#total-group {
border-style: none;
text-align: center;
position: fixed;
right: 10%;
top: 20%;
width: 8em;
}
#total-group legend {
display: none;
}
#total-label {
margin-bottom: 0.75em;
margin-left: 0;
width: auto;
}
}
</style>
</head>

<body>
<h1>Computer A</h1>
<form id="order" action="" method="post">
<fieldset><legend>Processor</legend>
<label><input name="processor" type="radio" value="0" checked>
Default option</label>
<label><input name="processor" type="radio" value="50">
Upgrade 1 ($50.00)</label>
<label><input name="processor" type="radio" value="100">
Upgrade 2 ($100.00)</label>
</fieldset>
<fieldset><legend>Memory</legend>
<label><input name="memory" type="radio" value="0" checked>
Default option</label>
<label><input name="memory" type="radio" value="50">
Upgrade 1 ($50.00)</label>
<label><input name="memory" type="radio" value="100">
Upgrade 2 ($100.00)</label>
</fieldset>
<fieldset><legend>Hard Drive</legend>
<label><input name="hard-drive" type="radio" value="0" onClick="function()" checked>
Default option</label>
<label><input name="hard-drive" type="radio" value="50" onClick="function()">
Upgrade 1 ($50.00)</label>
<label><input name="hard-drive" type="radio" value="100">
Upgrade 2 ($100.00)</label>
</fieldset>
<fieldset id="total-group"><legend>Total</legend>
<label id="total-label">Your total:
<input id="total" type="text" value="$0.00"></label>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</fieldset>
</form>
<script type="text/javascript">

Number.prototype.toCurrency = function(c, t, d) {
var n = +this,
s = (0 > n) ? '-' : '',
m = String(Math.round(Math.abs(n))),
i = '',
j, f;
c = c || '';
t = t || '';
d = d || '.';

while (m.length < 3) {m = '0' + m;}
f = m.substring((j = m.length - 2));
while (j > 3) {i = t + m.substring(j - 3, j) + i; j -= 3;}
i = m.substring(0, j) + i;
return s + c + i + d + f;
};

if(document.getElementsByName) {
(function() {
var E = document.forms.order.elements,
T = E.total;

function calculateTotal() {
var t = 0,
e, v;

if((e = getChecked('processor', this.form, 'radio'))) {t += +e.value;}
if((e = getChecked('memory', this.form, 'radio'))) {t += +e.value;}
if((e = getChecked('hard-drive', this.form, 'radio'))) {t += +e.value;}

T.value = (t * 100).toCurrency('$');
}
function getChecked(gN, f, t) {
var g = document.getElementsByName(gN);
t = t || 'checkbox';

for(var i = 0, n = g.length, c; i < n; ++i) {
if((t == (c = g[i]).type) && c.checked && (f == c.form)) {return c;}
}
}

for(var i = 0, n = E.length; i < n; ++i) {
if('radio' == E[i].type) {
E[i].onchange = calculateTotal;
}
}
E = null;
})();
}

</script>
</body>
</html>
Dec 10 '06 #1
2 4293
mybay
7
Why not do something like that, and it works in firefox :)

<script type="text/javascript">
document.forms['order'].onclick = DoMath;
var total;
function DoMath(){
total = 0;
for(i = 0; i < document.forms[0].length; i++)
if(document.forms[0][i].type == 'radio')
if(document.forms[0][i].checked){
total += parseInt(document.forms[0][i].value);
}
document.forms[0]['total'].value = "$" + total;
}

</script>
Dec 11 '06 #2
alexphd
19
Thanks a lot my bay "onclick" seemed to do the trick.



Why not do something like that, and it works in firefox :)

<script type="text/javascript">
document.forms['order'].onclick = DoMath;
var total;
function DoMath(){
total = 0;
for(i = 0; i < document.forms[0].length; i++)
if(document.forms[0][i].type == 'radio')
if(document.forms[0][i].checked){
total += parseInt(document.forms[0][i].value);
}
document.forms[0]['total'].value = "$" + total;
}

</script>
Dec 11 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
14
by: David Blickstein | last post by:
I have some XML documents that I want to open in a web browser and be automatically translated to HTML via XSLT. I'm using an xml-stylesheet processing command in a file called "girml.xml". ...
3
by: Jim | last post by:
I had Firefox set as my default browser, but I wanted to change back to IE when testing my webservices. Easy enough....(in IE) Tools>Internet Options>Programs then check "Internet Explorer...
15
by: KBuser | last post by:
I recently developed an internal website with various queries against our SQL server. I added buttons with Response.Redirect. These buttons do not work with Internet Explorer, however when using...
3
by: KBuser | last post by:
I recently developed an internal website with various queries against our SQL server. I added buttons with Response.Redirect. These buttons do not work with Internet Explorer, however when using...
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
3
by: google | last post by:
I am trying to complete a javascript application and am having problems with code similar to that show below. Much testing has shown that Firefox finishes the code shown in around 0.25 secs but...
9
by: =?Utf-8?B?Sm9obiBCYWlsZXk=?= | last post by:
I have a ASP .Net page that allows moving around items on the page through javascript. This page works fine in IE. In FireFox however, I have found that if the page is using XHTML 1.0...
2
by: JDeats | last post by:
>From my development envrionment (i.e. a single WinXP notebook PC) I have a basic AJAX application that is making the call to a Windows Form page that just returns the request back to the AJAX...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.