0

I created a script when you can buy shirts, pants, etc.... The problem I am having is that when I run this script on my website it works perfectly. However, when I run it using JSFiddle, it doesn't work at all. I don't understand what I am dong wrong and I have other scripts on fiddle that work fine. I would appreciate it if someone can take a look at it and tell me where I made a mistake. Thank You.

JS Fiddle - http://jsfiddle.net/rissandimo/Lo6jsuvu/

My Website - http://omidnassir.com/programs/shirts/shirts.html

  • So, no dickishness intended... The expected result would help. what is your definition of "working?" – Todd Dec 02 '14 at 01:39
  • Possible duplicate of http://stackoverflow.com/questions/5468350/javascript-not-running-on-jsfiddle-net – outlyer Dec 02 '14 at 01:46
  • Agreed, this is an exact duplicate of that issue. The answer to that question explains the solution better than any of the answers here. – GregL Dec 02 '14 at 01:49
  • Well I am a beginner at JavaScript, so I don't yet understand classes and prototypes fully to comprehend what's happening in more advanced scripts. –  Dec 02 '14 at 01:52

2 Answers2

0

It is working now.

Problem with JSFiddle setting.

I set it to No Wrap - Body. Your setting is different and it is on load so at that time element is not present so JS Function is not bind at that time.

dotnetstep
  • 17,065
  • 5
  • 54
  • 72
0

You need to select either of the "No wrap" options for where to place your Javascript (the second dropdown in the top left panel).

annotated screenshot showing dropdown

This is because you had it set to "onLoad", which means that your Javascript will be placed within a function that runs when the document is loaded, and will not create functions in the global scope. This is why when you try to click the button, it complains that "addToBasket() not defined".

GregL
  • 37,147
  • 8
  • 62
  • 67