Javascript calculator issue with html

Javascript calculator issue with html

Page 1 of 1

5 Replies - 1080 Views - Last Post: 30 October 2009 - 04:33 AM

#1 bones2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-October 09

Javascript calculator issue with html

Post icon  Posted 29 October 2009 - 11:50 AM

The following code I received to add a java calc to my site. On its own without anything it works 100%, but as soon as I put it into a specific place in my index page and preview it in browser then it removes everything located under this script (like footer and info after)

Is the code wrong or my pc's settings?


[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
/**
* Note the keys here relate directly to the values you use
* in the product selection dropdown.
*/
prices = {
'0' : 0,
'1' : 400,
'2' : 600,
'3' : 5
}

gebi = function(id) { return document.getElementById(id); }

window.onload = updatePriceDisplay = function()
{
gebi('total_price').innerText = (prices[gebi('product').value] * gebi('quantity').value).toFixed(2);
}
</script>
</head>
<body>
<p>
<select id="product" onchange="updatePriceDisplay()">
<option value="0">Choose your Camper</option>
<option value="1">5 Seater</option>
<option value="2">8 Seater</option>
</select>
</p>
<p>
<select id="quantity" onchange="updatePriceDisplay()">
<option value="0">How many travel days</option>
<option value="1">1 day</option>
<option value="2">2 days</option>
<option value="3">3 days</option>
</select>
</p>
<p><span id="total_price" /></p>

</body>
</html>[code]

Is This A Good Question/Topic? 0
  • +

Replies To: Javascript calculator issue with html

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Javascript calculator issue with html

Posted 29 October 2009 - 11:54 AM

Note: Java is not the same as Javascript.

*** Thread moved to Javascript ***
Was This Post Helpful? 0
  • +
  • -

#3 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Javascript calculator issue with html

Posted 29 October 2009 - 05:25 PM

Change this line:
window.onload = updatePriceDisplay = function() {
  gebi('total_price').innerHTML = 
	(prices[gebi('product').value] * gebi('quantity').value).toFixed(2);
}


Works fine then in FF. Not tested in MSIE.

Good Luck!
:)
Was This Post Helpful? 0
  • +
  • -

#4 bones2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-October 09

Re: Javascript calculator issue with html

Posted 30 October 2009 - 01:44 AM

View PostJMRKER, on 29 Oct, 2009 - 04:25 PM, said:

Change this line:
window.onload = updatePriceDisplay = function() {
  gebi('total_price').innerHTML = 
	(prices[gebi('product').value] * gebi('quantity').value).toFixed(2);
}


Works fine then in FF. Not tested in MSIE.

Good Luck!
:)


Thanks for the fast reply, but it still doesn't work.
When I add it and view in IE it shows "To help protect your security, Internet Explorer has restricted ..." and the whole page shows but without the total number.
As soon as I let the Active Script run then the total shows but without everything on the site underneath it.
Was This Post Helpful? 0
  • +
  • -

#5 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Javascript calculator issue with html

Posted 30 October 2009 - 02:27 AM

Try lowering your security level or run the page from a webserver instead. IE is a lot more picky about running javascript locally.
Was This Post Helpful? 0
  • +
  • -

#6 bones2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-October 09

Re: Javascript calculator issue with html

Posted 30 October 2009 - 04:33 AM

Thanks - I'll give this a go later. Best would be to upload to web server instead of trying to figure out my pc's security.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1