CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2006
    Posts
    15

    Unhappy Delegate in javascript

    hello,
    I would like to know if it is possible to use delegate in javascript and if so how to do it.
    (I want to send to a function a pointer to other function and raise that pointer).

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Delegate in javascript

    What do you mean by delegate? I assume you are talking about a functionality of another programming language. Could you please explain more?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2006
    Posts
    15

    Re: Delegate in javascript

    In C# for example I can declare a delegate and pass to it a function from a different class and in the class where I declared the delegate I can raise an event and activate that function. I would like to know if it is possible to do it in javascript.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Delegate in javascript

    To a person who knows C#, that is clear but to a person who knows scripting, that is not. Can you give a code example maybe?

    Is a delegate a variable? What do you mean "raise" an event?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2006
    Posts
    15

    Re: Delegate in javascript

    First I want to apologize if I insulted you. In my code a draw a table and inside one of it’s row I draw an input. Because I draw this table for different purpose I need to connect the onfocusout event to different functions (each time to one function) and I need to be able to activate that function when the input loses focus.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Delegate in javascript

    No. There was no insult. Okay, I think I understand what you are saying.

    In the <input> tag, you can add an event called onblur. This will occur when the object loses focus. Just add the function there.

    Code:
    <input type="text" name="blah" onblur="function(variable if any)">
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Nov 2006
    Posts
    15

    Re: Delegate in javascript

    my problem is that i need to add the function dynamically. I need to do:
    getElementById('string').onblur = function(parameters).
    when the function is different each time.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Delegate in javascript

    So do it that way.

    Code:
    document.getElementById('OBJECT ID').onblur = function(){
     // do what you want here...
    }
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured