Results 1 to 4 of 4

Thread: Problem with function arguments

  1. #1
    Join Date
    Jul 2010

    Problem with function arguments

    I have such function:

    function trigger() {
      var trigger_arg_1 = arguments[0];
      arguments[0].change( function (trigger_arg_1) {
      mainFunction(trigger_arg_1); // now I need to pass the object like "sk" to mainFunction()
      return false;
    And activating code:
    window.onload = function() {
      // ... and other objects here
      trigger(sk); // to assign a event to sk.object
      // ... and other event assignments here
    This should to assign event onchange to object sk. Onchange call mainFunction(). Here I need to pass the object like "sk" or similar to mainFunction(). Problem happened. I debug mainFunction():

    console.log(thisEl.type); // shows "change"
    console.log(thisEl); // * shows event object

    * - I think here should be the element object, not the function... I used to use this for "select" elements and it work. But I did some little changes with JS and now does not. So I need to find some way how to fix it. Maybe somebody would help me?


  2. #2
    Join Date
    Aug 2007
    $(this) is the normal way to refer to the element in jQuery. And I reiterate my advise from the earlier thread, and add to it. I'd suggest that you learn to do this sort of thing with standard DOM methods first, then use a library.

  3. #3
    Join Date
    Jul 2010
    I have learned the anonymouse functions.

    Maybe better solution would be to call that function as so:

    sk.trigger(); // this would assign mainFunction to onchange event of sk object

    But I don't how to do It. There is another point of view. I use the main function on other way:

    <input id="xx1" name="xx1" type="text" onkeyup="mainFunction('restart', event, this)">
    I would need a suggestion what code structure to use.

    I think the main thing of trigger function is that it needs the argument of what object I want to assign main function to. There for trigger(sk);

    Maybe this would be correct solution?
      sk.onchange = mainFunction(sk);
    Last edited by crazy boy; 07-31-2010 at 05:38 AM.

  4. #4
    Join Date
    Aug 2007
    No, that assigns the value of mainFunction to sk.onchange, which would only be correct if mainFunction returns a function. You probably want this.
    sk.onchange = function () {
    If you want access to e (window.event in IE), you'll need to pass that manually to mainFunction.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles