...

View Full Version : Uncaught ReferenceError: btnClick is not defined



cicily
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.







<html>
<head>
<script type="text/javascript">

var c1 = new Calculator("tab1");
//alert(c1);

var c2 = new Calculator("tab2");



function Calculator(id)
{

var elm = document.getElementById(id);
if (elm.attachEvent)
{
elm.attachEvent('onclick', btnClick);
}
else
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 = '';
}
else
{
document.getElementById('disply').value += buttonValue;
}
}
focus();

}
function focus() {

document.getElementById("disply").focus();
}

</head>

<body>
<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>
<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>
</tr>
</table>

</body>
</html>





_______________________


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

Dormilich
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum