Solved

Javascript in IE7

Posted on 2013-02-05
3
354 Views
Last Modified: 2013-02-05
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

0
Comment
Question by:ncw
3 Comments
 
LVL 13

Accepted Solution

by:
stergium earned 500 total points
ID: 38854719
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
 
LVL 82

Expert Comment

by:leakim971
ID: 38854738
try to clear the ie7 browser cache and reopen the page
0
 
LVL 1

Author Closing Comment

by:ncw
ID: 38855665
onclick worked, thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question