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 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    São Paulo, BRAZIL
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i call an event from code?

    Hello folks, i have some text fields in some web page, and each text field has its event onBlur one method named onBlur_doSomething( ), i´d like to known how can i call those event from code? Something like:

    var frm = document.forms[ 0 ];

    for ( var i = 0; i < frm.elements.length; i++ )
    {
    if ( frm.elements[ i ].type == "text" )
    frm.elements[ i ]onblur( ); // I really don´t known how:
    }


    Regards,
    lottalava

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    onBlur_doSomething( ) looks like a function, not a method, so I confess I don't understand your problem. Can u detail, please?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2002
    Location
    São Paulo, BRAZIL
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onBlur_doSomething( ) is a function that i bind as onClick´s event of all textfield ( <input type="text"> ) that i have in my page, all i want is call this method from code because it starts some task for each textfield.

    Regards,
    Edson

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:
    Code:
    frm.elements[ i ].blur( );
    /Daniel

  • #5
    New Coder
    Join Date
    Oct 2002
    Location
    São Paulo, BRAZIL
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is right, but if textfield is disabled it don´t work.

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then you need to check if it's disabled first:
    Code:
    if (!frm.elements[i].disabled) {
        frm.elements[i].blur();
    }
    /Daniel

  • #7
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    or...
    Code:
    function foo() {
    //blah...
    }
    document.getElementById('textbox').onClick = foo; //or onBlur, etc
    //when wanting to be called:
    foo();
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!


  •  

    Posting Permissions

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