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

3
  • click the JsLint button and you will see coding errors Commented Feb 2, 2012 at 15:17
  • missing ) after argument list }); /_display/ (line 66, col 4) You have js errors. Commented Feb 2, 2012 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. Commented Feb 2, 2012 at 15:30

2 Answers 2

128

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

It took me a while to figure this out.

Sign up to request clarification or add additional context in comments.

3 Comments

awesome! Can you explain what exactly this does? what does wrap mean with regards to onLoad()?
What is "Frameworks & Extensions" ?? i don't see that anywhere.
Click on the settings icon next to JAVASCRIPT in the JAVASCRIPT panel and choose 'no wrap - in <body>'
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.

1 Comment

Although the above answer tells us how to fix the issue, I upvote yours because you explain what is going on :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.