Reputation: 13988
I have the following HTML Code.
<select onChange="TestCall()">
<option>Text1</option>
<option>Text2</option>
<option>Text3</option>
<option>Text4</option>
</select>
My JavaScript have a simple alert message like below.
function TestCall()
{
alert("Test");
}
Check the following Jsfiddle. I have added my script in the javascript area of jsfiddle. It is not working.
But If i move script block inside the HTML area of jsfiddle is working. Check the below one.
What wrong in my code? Any Idea?
Upvotes: 0
Views: 190
Reputation: 145388
By default JSFiddle wraps the JS block into onLoad
function:
... leading to something like:
window.onload = function() {
function TestCall() {
alert("Test");
}
};
This means that your TestCall
method is getting out of global scope and is not accessible from HTML attributes.
Change the option to No wrap - in <head>
or No wrap - in <body>
and it will work.
DEMO: http://jsfiddle.net/Q9ukX/3/
Upvotes: 4