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>
LVL 4
rbartzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
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
0
leakim971PluritechnicianCommented:
work fine for me on IE10 : http://jsfiddle.net/NwGFE/
0
RobOwner (Aidellio)Commented:
Works for me as well on IE10 compatibility mode
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Julian HansenCommented:
I can replicate the problem in IE8.

It appears to be a problem with the variable 'gpm' - not sure why IE8 is seeing gpm beging special (shows undefined if you alert it) - but that's MS for you.

If you do this in your function it should work
function calcGpm() {
 var dia = document.forms[0].dia.value;
 var horz = document.forms[0].horz.value;
 var vert = document.forms[0].vert.value;
 var gpm = 0;   // ADD THIS
 var gpm2 = 0; // NOT NECESSARY TO MAKE SCRIPT WORK BUT ADD FOR COMPLETENESS
 
 gpm = 10;//(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);
      }
 }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rbartzAuthor Commented:
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
0
Julian HansenCommented:
You are welcome - thanks for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.