html - JavaScript 'function undefined' error working with jsfiddle -


i'm trying understand error because can around , other times can't. i've tried writing function:

function togglebutton() { } 

but same error. .js sample.

var checkbox = document.getelementbyid("chkmybox");    checkbox.onclick = function togglebutton(e, obj1)   {     var btnelement = document.getelementbyid("btnmybutton");     if(btnelement != null) {         alert("element not null");     if(e.target.checked && obj1 != null) {         alert("checking check " + obj1.checked);          if(obj1.checked == true && btnelement.getattribute('disabled') == false){             btnelement.getattribute('disabled') = false;         } else {                 btnelement.getattribute('disabled') = true;         }      }   }   } 

here's html:

<form id="frmcheckbox">    <input type="checkbox" id="chkmybox" />        <button id="btnmybutton" disabled>i'm button</button> </form> 

http://jsfiddle.net/arandolph0/h8re6/3/

change line uses name:

<input type="checkbox" name="chkmybox" />     

into using id instead:

<input type="checkbox" id="chkmybox" />     

alternatively use:

var elements = document.getelementsbyname('chkmybox'); var element = elements[0]; //first element name in array 

or

var element = document.getelementsbyname('chkmybox')[0]; 

update (as op changed code original question):

function togglebutton(e, obj1)  

this won't work there single argument given callback function (e). use e.target element.


Comments