0

So, i am in the midst of making a little website where you can calculate right angled triangles. Y'know, just for the fun of it.

Atm, i'm testing the real time calculation of the different html forms, however, i can't figure out why the form for cathetusB isn't updating.

Any help is appreciated!

This is how all the forms are set up: <input type="number" step="0.01" id="someID" onkeyup=calculate();>

The JS code messed up when i tried to paste it in, so here's a fiddle!

EDIT: Added all the code to the Fiddle!

2 Answers2

1

You have configured JSFiddle so that the code runs in an onload event handler.

The functions are therefore scoped to that handler function.

They are not globals.

They are not accessible to your intrinsic event handlers.

Configure JSFiddle to place the JS in the body instead of onload and the code works.

JSFiddle configuration

It would be better to replace your intrinsic event handler attributes with programatic event binding.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
  • That is really weird. It works when i run it in JSFiddle, but not when i run it locally.. Any idea on why that could be? – Elias Jørgensen Dec 04 '14 at 20:42
  • No. I can't see your local code. The JavaScript console in your browser might have some useful error messages though. – Quentin Dec 04 '14 at 20:43
  • The code is exactly the same, which is why it's so weird. Except for the part, that i load the JS as an external file.. – Elias Jørgensen Dec 04 '14 at 20:45
  • Chrome gives me the error "Uncaught TypeError: Cannot set property 'value' of null", when i type something in the input form. Its very strange.. – Elias Jørgensen Dec 04 '14 at 20:51
  • Presumably, then, the code is not the same. The script is in a different place. http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element – Quentin Dec 04 '14 at 21:00
  • Thanks for the link! Moving the script's "link" to the bottom of the body fixed it! – Elias Jørgensen Dec 04 '14 at 21:04
0

Be careful when using this :

<input type="number" step="0.01" id="cathetusA" onkeyup=calculate();>

If you are using the same id with every form things your code will not work. Id must be unique for every object

stranger4js
  • 241
  • 4
  • 14