0

I'm trying to run a function called "fn" with the onchange event, change the dropdown options. but this error to me (index): 190 Uncaught ReferenceError: fn () is not defined. Why is this happening?. I'm sure my function exists.

this is my code:

<div id="chart"></div>
<select id='dropdown' onchange="fn();">
 <option value='1'>data1</option>
 <option value='2'>data2</option>
 <option value='3'>data3</option>
</select>

function fn(){
 ...

https://jsfiddle.net/yvvxbhn3/

APerson
  • 8,140
  • 8
  • 35
  • 49
  • Do you have the declaration of `fn()` inside of a [` – APerson Mar 29 '16 at 01:47
  • 1
    Where is your function defined? – Angelo DeMichaels Mar 29 '16 at 01:47
  • 1
    It is because your fiddle is set up wrong. The fiddle is set to be run onload and that means your function is NOT in global scope. – epascarello Mar 29 '16 at 01:48
  • You need to pass in THIS. ie: fn(this). "This" points to the select statement. OR if you use jQuery you use the $("dropdown") to get what you are working with. On the THIS: the onchange="fn(this);" and the function statement is function fn(e){. Where the "e" is for Element. :-) – Mark Manning Mar 29 '16 at 01:48
  • @APerson you just removed the problem.... And created a new one. Fiddle was the issue. – epascarello Mar 29 '16 at 01:50
  • @epascarello Oops, will revert. (And that's probably a "typographical issue" flag, then, too.) – APerson Mar 29 '16 at 01:51
  • @APerson jsFiddle not know well the page. but my role was the part where this javascript code. That's wrong? –  Mar 29 '16 at 01:52
  • @epascarello pardon my ignorance. I do not understand. how I can corregirlo.no I am familiar with jsdfiddle –  Mar 29 '16 at 01:53
  • click the gear icon beside the word javascript, change onload to head or body. Your code still has other issues, but that will clear up the issue you have. – epascarello Mar 29 '16 at 01:54
  • @epascarello it works now!. thank you very much. –  Mar 29 '16 at 02:02

0 Answers0