0

This is driving me crazy. I cannot figure out why I get "mytest is not defined" error:

here's the fiddle --> http://jsfiddle.net/y7MTs/5/

HTML:

<span>One: </span>
  <input type='text' id='ax' value='4' size='6'/>
  <br/>

<span>Two: </span>
  <input type='text' id='bx' value='2.5' size='6'/>
  <br/><br/>

<button onclick='mytest(ax.value, bx.value);'>Go Now</button>

Javascript:

function mytest(a, b) {
  var x = [0, 1, 2, 3, 4, 5];
  var y = [100, 120, 140, 160, 180, 200];

  var myval = parseFloat(a) - x[3];
  alert(myval);    

}
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Sanya
  • 1,270
  • 5
  • 21
  • 47

1 Answers1

7

In your fiddle, the function is in the scope of a callback which is given to the onload event handler.

In the menu at top left, choose no wrap - in <head>.

Fixed fiddle : http://jsfiddle.net/dystroy/FrVE6/

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758