Link to home
Start Free TrialLog in
Avatar of rbartz
rbartz

asked on

Javascript Division in IE10 compatibility mode

Can someone tell me why the following function works in Firefox, Chrome, and IE10 but NOT when running IE10 in compatibility mode?

The error in console is here:   gpm = (dia*dia*2.56*horz)/Math.sqrt(vert);

The error is SCRIPT438: Object doesn't support this property or method

<script type="text/javascript">
function calcGpm() {
 var dia = document.forms[0].dia.value;
 var horz = document.forms[0].horz.value;
 var vert = document.forms[0].vert.value;
 
 gpm = (dia*dia*2.56*horz)/Math.sqrt(vert);
 gpm2 = Math.round(gpm*Math.pow(10,2))/Math.pow(10,2);
 if(gpm2 > 0 ) {
       document.getElementById('gpm').innerHTML = '<b>'+gpm2+'</b>';
      document.getElementById('gph').innerHTML = commafyNumber(gpm2*60);
      document.getElementById('gpd').innerHTML = commafyNumber(gpm2*1440);
      }
 
}
function commafyNumber( number ) {
  number = '' + number
  var withcommas = number.replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
    return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,")
  })
  return withcommas
}
</script>
Avatar of Rob
Rob
Flag of Australia image

Is like you to try this site to determine whether it is that line of code or something in your script
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_sqrt3
work fine for me on IE10 : http://jsfiddle.net/NwGFE/
Works for me as well on IE10 compatibility mode
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rbartz
rbartz

ASKER

Julian H,

That was it!  var gpm must be something special to javascript somewhere in older versions of IE.  Changed it to gpm1 and now the script works in all browsers as it should have!

Thank you Julian!  And thanks to tagit and leakim971 for trying.

Richard
You are welcome - thanks for the points.