Javascript in IE7

I am having a problem with some javascript. It seems to work on Chrome and IE9 but not in IE7. There are several radio options in the code below, one selects the product type (Battery, rechargeable or wired) and another selects the payment option (1 or 3 year package). The selections of these two controls should then set the price, but IE7 gets the result wrong in every case. It even gets a different answer for the same selections depending what happened before.

Clicking the sub, vat or total boxes, the values change to the correct value. Any ideas please?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>some title</title>
<!--  <link rel="stylesheet" media="screen" href="basic.css"> -->
  <link rel="stylesheet" media="screen", media="screen and (max-width:800px)" href="basic.css">
  <link rel="stylesheet" media="screen and (min-width:801px) and (max-width:1000px)" href="medium.css">
  <link rel="stylesheet" media="screen and (min-width:1001px)" href="wide.css">
  <!--[if (IE 8)|(IE 7)]>
    <link rel="stylesheet" media="screen" href="medium.css">
  <![endif]-->
  <script type="text/javascript">
  document.createElement('header');
  document.createElement('footer');
  document.createElement('nav');
  function delAddr()
  {
	if (document.getElementById("alt").checked)
	{
		document.getElementById("withDelivery").value="true";
	}
	else
	{
		document.getElementById("withDelivery").value="false";
	}
  }

  function calc()
  {
  debugger;
    price = 0;
	if (document.getElementById("batt").checked)
	{
		if (document.getElementById("oneyr").checked)
			price=301.00;
		else
			price=600.00;
	}
	else if (document.getElementById("rech").checked)
	{
		if (document.getElementById("oneyr").checked)
			price=350.00;
		else
			price=650.00;
	}
	else/* if (document.getElementById("wire").checked)*/
	{
		if (document.getElementById("oneyr").checked)
			price=400.00;
		else
			price=700.00;
	}
	sub = price;
	vat = sub * 0.2;
	price = price + vat;
	document.getElementById("subTot").value = sub.toFixed(2);
	document.getElementById("vat").value = vat.toFixed(2);
	document.getElementById("cost").value = price.toFixed(2);
  }
  </script>
</head>
<body id="buy">
  <div id="wrapper">
	<img id="top" src="tophome.jpg" alt="">
	<div id="wrapper2">
	  <div id="main">
		  <p>Some text</p>
		  <div id="buybox">
		  <form>
			<input type="hidden" name="instId"  value="210107">
			<input type="hidden" name="cartId" value="WS-01">
			<input type="hidden" name="currency" value="GBP">
			<input type="hidden" name="hideCurrency">
			<input type="hidden" name="desc" value="" id="desc">
			<input type="hidden" name="testMode" value="0">
			<input type="hidden" id="withDelivery" name="withDelivery" value="false">
			<h2>Buy</h2>
			<p>Buy button takes you to the Worldpay Secure Server to enter your details safely</p>
			<p><em>type:</em></p>
			<p><label for="batt">Battery</label><input type="radio" id="batt" name="moption" value=0 checked="checked" onchange="calc()"></p>
			<p><label for="rech">Rechargeable</label><input type="radio" id="rech" name="moption" value=1 onchange="calc()"></p>
			<p><label for="wire">Wired</label><input type="radio" id="wire" name="moption" value=2 onchange="calc()"></p>

			<p><em>Payment option:</em></p>
			<p><label for="oneyr">1 year</label><input type="radio" id="oneyr" name="payoption" value=0 checked="checked" onchange="calc()"></p>
			<p><label for="threeyr">3 year</label><input type="radio" id="threeyr" name="payoption" value=1 onchange="calc()"></p>

			<p><em>Deliver to:</em></p>
			<p><label for="card">Card Address</label><input type="radio" id="card" name="deloption" value=0 checked="checked" onchange="delAddr()"></p>
			<p><label for="alt">Alternate Address</label><input type="radio" id="alt" name="deloption" value=1 onchange="delAddr()"></p>

			<p><label>Sub Total &pound</label><input type="text" id="subTot" name="subTot" readonly="readonly" value=0></p>
			<p><label>Vat &pound</label><input type="text" id="vat" name="vat" readonly="readonly" value=0></p>
			<p><label>Total &pound</label><input type="text" id="cost" name="cost" readonly="readonly" value=0></p>
		    <div class="clear"></div>
			<input type="submit" value="Buy Now" name="SUBMIT">
		  </form>
		  </div>
	  </div>
	</div>
  </div>
</body>
</html>

Open in new window

LVL 1
ncwAsked:
Who is Participating?
 
stergiumConnect With a Mentor Commented:
Hello.
there is a bug in IE7 about onchange event
http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/958a24b7-775e-434b-9fd4-58f72ecbb759/
you can use onclick or onblur event.
hope that helps
0
 
leakim971PluritechnicianCommented:
try to clear the ie7 browser cache and reopen the page
0
 
ncwAuthor Commented:
onclick worked, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.