View Full Version : Uncaught ReferenceError: btnClick is not defined

05-30-2012, 06:59 AM
Hi I am getting an error that a particular method btnClick is not defined, Where i Have defined it.

<script type="text/javascript">

var c1 = new Calculator("tab1");

var c2 = new Calculator("tab2");

function Calculator(id)

var elm = document.getElementById(id);
if (elm.attachEvent)
elm.attachEvent('onclick', btnClick);
elm.addEventListener("click", btnClick, false);


Calculator.prototype.btnClick = function() {
var button = e.target||e.srcElement;
var buttonValue = button.value;
if(buttonValue != "=")
if (buttonValue == "CE")
document.getElementById('disply').value = '';
document.getElementById('disply').value += buttonValue;

function focus() {



<table id="tab1" border="4" align="center" bordercolor="grey" bgcolor="#E8E8E8" cellpadding="4">
<tr> <td colspan="4"><input id="disply1" type="text" size="27" onkeypress="return onlyNumbers(event);" /></td> </tr>
<td><input class="btnStyle" type="button" Value="7" /></td>
<td><input class="btnStyle" type="button" Value="8" /></td>
<td><input class="btnStyle" type="button" Value="9" /></td>
<td><input class="btnStyle" type="button" Value="/" /></td>



pls help..
Why this happens when method is defined.
Is it wrong way to define.

05-30-2012, 08:35 AM
it is the wrong way to access. what you have defined is a method of the Calculator object. what you request is a global function. you would have to access the method as this.btnClick.