OnChange event handler question..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xoinki
    New Member
    • Apr 2007
    • 110

    OnChange event handler question..

    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..
    Code:
    // if not defined
    a = new Object()
    //if not defined
    a.b = new Object()
    a.b.init = function()
    {
      var vproto = a.b.Init.prototype;
       var vthis = this;
       vproto.somefunction = function()
       {
       }
       vproto.eventhandler = function()
       {
       }
    }
    
    // so eventhandler is the onChange event handler
    Now, my HTML looks somewhat like this..
    Code:
    <html>
    ...
    ..
    <.... onchange = a.b.eventhandler;>
    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
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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

    Comment

    • xoinki
      New Member
      • Apr 2007
      • 110

      #3
      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

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        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:

        [CODE=javascript]/**
        * constructor of class OBJ
        */
        function OBJ() {
        // a priv variable
        var foo = 'bar';

        // a public variable
        this.foobar = 'barfoo';

        // a privileged method to access the priv variable
        this._get_foo = function() {
        return foo;
        }
        }

        /**
        * extending the prototype
        */
        OBJ.prototype.a _method = function(params ) {
        // code of the method
        }

        // later on we may instantiate the obj
        var obj = new OBJ;

        // and call a_method
        obj.a_method();
        [/CODE]
        kind regards

        Comment

        • xoinki
          New Member
          • Apr 2007
          • 110

          #5
          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.

          Code:
          function OBJ() 
          {
                    // a priv variable
                    var vFoo = 'bar';
                    // a public variable
                    this.vfFooBar = 'barfoo';
                    // a privileged method to access the priv variable
                     var vPrototype = OBJ.prototype;
          
                  vProto.a_method = function(params) 
                   {
                    // code of the method
                   }
           }
          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

          Comment

          Working...