Update your fiddle to use no wrap - in <head>
or no wrap in <body>
or jsFiddle will wrap the script by default into a window.onload
. Which causes the elements to render first and as the onclick
is rendered the script does not exists yet as it only gets added after the window is loaded, like this:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>- jsFiddle demo</title>
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type="text/css">
</style>
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
function test() {
alert("TEST");
}
function arrayOfOandZ(size) {
var arrayOFOnZ = new Array(size);
//Fill array
for (var x = 0; x < size; x++) {
arrayOfOnZ[x] = size % 2;
}
alert(arrayOFOnZ.join('\n'));
}
} //]]>
</script>
</head>
<body>
<input type="button" value="5 Items" onclick="test()">
<input type="button" value="6 Items" onclick="arrayOfOandZ(6)">
<input type="button" value="7 Items" onclick="arrayOfOandZ(7)">
</body>
</html>
DEMO - Fixed settings in fiddle
no wrap in <head>
for example renders the script directly into the head
without the window.onload
wrapper making it available immediately. Therefore when the elements get rendered the script exists, like this:
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>- jsFiddle demo</title>
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type="text/css">
</style>
<script type="text/javascript">
//<![CDATA[
function test() {
alert("TEST");
}
function arrayOfOandZ(size) {
var arrayOFOnZ = new Array(size);
//Fill array
for (var x = 0; x < size; x++) {
arrayOfOnZ[x] = size % 2;
}
alert(arrayOFOnZ.join('\n'));
}
//]]>
</script>
</head>