Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Uncaught ReferenceError: btnClick is not defined

    Hi I am getting an error that a particular method btnClick is not defined, Where i Have defined it.


    Code:
    
    
    <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.
    Last edited by cicily; 05-30-2012 at 06:28 AM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,134
    Thanks
    12
    Thanked 332 Times in 328 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •