user1935041
user1935041

Reputation: 3

Javascript function undefined when called from input image onclick event

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

Upvotes: 0

Views: 125

Answers (2)

Wio
Wio

Reputation: 1251

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.

Upvotes: 0

weeklyTea
weeklyTea

Reputation: 345

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.

Upvotes: 1

Related Questions