469,309 Members | 2,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,309 developers. It's quick & easy.

OnChange event handler question..

110 100+
hi all,
I am trying to attach an event to onChange property..
the function i am trying to attach is inside a class.
for eg..
my js has a structure as follows..
Expand|Select|Wrap|Line Numbers
  1. // if not defined
  2. a = new Object()
  3. //if not defined
  4. a.b = new Object()
  5. a.b.init = function()
  6. {
  7.   var vproto = a.b.Init.prototype;
  8.    var vthis = this;
  9.    vproto.somefunction = function()
  10.    {
  11.    }
  12.    vproto.eventhandler = function()
  13.    {
  14.    }
  15. }
  16.  
  17. // so eventhandler is the onChange event handler
  18.  
Now, my HTML looks somewhat like this..
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. ...
  3. ..
  4. <.... onchange = a.b.eventhandler;>
  5.  
here it is not throwing up any errors.. but the event handler is not called..
please help me how to call this event handler inside the object?

Waiting for u r reply,
Xoinki
Feb 18 '08 #1
4 1387
gits
5,390 Expert Mod 4TB
hi ...

could you please explain what that code should do with that init() and Init.prototype? I assume you try to create a class but it seems little bit weird ... so explain the concept that you wish to use?

kind regards
Feb 18 '08 #2
xoinki
110 100+
hi!
Thnx for replying, I got the solution.
What i am trying to do here is.. to disable/enable some elements based on select element change. I was trying to do the wrong way here.. I cannot call a eventhandler which is a member function of a class from HTML.. since i would require an instance of that class to access that handler.. the solution for this which i found out is to attach an event handler "onload" this solves the problem.

Thnx and regards,
Xoinki
Feb 19 '08 #3
gits
5,390 Expert Mod 4TB
glad to hear you got it working ... but i personally have a question about your class ... are you using any js-framework or how do you create your classes? i ask because a typical js-class is constructed as follows:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * constructor of class OBJ
  3.  */
  4. function OBJ() {
  5.     // a priv variable
  6.     var foo = 'bar';
  7.  
  8.     // a public variable
  9.     this.foobar = 'barfoo';
  10.  
  11.     // a privileged method to access the priv variable
  12.     this._get_foo = function() {
  13.         return foo;
  14.     }
  15. }
  16.  
  17. /**
  18.  * extending the prototype
  19.  */
  20. OBJ.prototype.a_method = function(params) {
  21.     // code of the method
  22. }
  23.  
  24. // later on we may instantiate the obj
  25. var obj = new OBJ;
  26.  
  27. // and call a_method
  28. obj.a_method();
  29.  
kind regards
Feb 19 '08 #4
xoinki
110 100+
hi!,
I am not using any JS framework. actually I am using classes exactly as you have mentioned above. Only thing is i am using it in different way.

Expand|Select|Wrap|Line Numbers
  1. function OBJ() 
  2. {
  3.           // a priv variable
  4.           var vFoo = 'bar';
  5.           // a public variable
  6.           this.vfFooBar = 'barfoo';
  7.           // a privileged method to access the priv variable
  8.            var vPrototype = OBJ.prototype;
  9.  
  10.         vProto.a_method = function(params) 
  11.          {
  12.           // code of the method
  13.          }
  14.  }
  15.  
etc.. I Write all member functions inside the class itself. This gives me better readability since I need not search for member functions in a js file.. I know which are member function and which are not.

Thanx and regards,
Xoinki
Feb 25 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.