0

This seems really simple but I can't get it working...

    function myfunction(id) 
    {
        alert("ID: " + id);
    }

There is a fiddle here http://jsfiddle.net/66ALW/

The error I get in Firebug is ReferenceError: myfunction is not defined http://fiddle.jshell.net/_display/ (1) Line 1

2
  • 1
    You have to set the "nowrap - in body" option on the jsfiddle control panel. Otherwise the code in the JavaScript pane goes into a wrapper function, so your "myfunction" ends up as a local function of that and isn't globally visible. Commented Jul 24, 2014 at 15:51
  • 1
    And that solves the problem — jsfiddle.net/66ALW/1 — it's a jsfiddle config issue, not a problem with the code. Commented Jul 24, 2014 at 15:53

2 Answers 2

1

You need set "No wrap in head" in jsfiddle to solve your problem: http://jsfiddle.net/66ALW/2/

function myfunction() 
{
    alert("Reached");
}

code is ok.

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

Comments

0

You are defining myfunction in the onLoad event, so it isn't being populated in the global namespace. Thus, function appears to not exist. There are two solutions.

  1. Manually put it into global namespace window.myfunction = myfunction;
  2. Configure jsfiddle to use 'no wrap' options in the frameworks and extensions section.

1 Comment

Thanks to all but 1. was the answer I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.