43

I'm testing some javascript on jsfiddle and for some reason I can't get a function to fire on a button click. Any advice?

jsfiddle link

Daniele B
  • 3,117
  • 2
  • 23
  • 46
Cronin O'M
  • 692
  • 1
  • 12
  • 19
  • click the JsLint button and you will see coding errors – Nicholas Murray Feb 02 '12 at 15:17
  • missing ) after argument list }); /_display/ (line 66, col 4) You have js errors. –  Feb 02 '12 at 15:20
  • 1
    I would also suggest that you use a framework like Backbone.js. You can create a 'Room' model and set its attributes - like price and room number. Then push those models into a Collection (sort of like a super-array that has some helpful methods). You can use it with JQuery and it would really help clean up your code. – PhillipKregg Feb 02 '12 at 15:30

2 Answers2

128

In the Frameworks & Extensions panel, set onLoad to No wrap - in <body>.

It took me a while to figure this out.

dk123
  • 18,684
  • 20
  • 70
  • 77
18

You have configured JSFiddle to wrap the code in an onload event handler. Consequently the function you are trying to call onclick is out of scope.

Don't use intrinsic event attributes. Use jQuery's (since you are using jQuery already) event binding instead.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335