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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2002
    Location
    France
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Validating a form by firing events

    This script allows you to replay the event-controls coded on your INPUT tags.

    You must have a <div id="msgErreur"></div> in your HTML page.

    PS : I'm working for an Intranet Webapp. All the users are on IE6.
    So i don't mind with NS compatibility

    -----------------

    // Wait the end of load before manipulating elements
    window.onload=doLoad;

    function doLoad() {
    if (document.forms.length > 0) {
    for(i=0;i<document.forms.length;i++) { document.forms[i].onsubmit=doSubmit; }
    }
    }

    function doSubmit() {
    if (document.all["msgErreur"]!=null) {
    if (document.forms.length > 0) {
    message=document.all.msgErreur.innerText;
    message='';
    for(i=0;i<document.forms.length;i++) {
    for(j=0;j<window.document.forms[i].elements.length;j++) {
    cible=window.document.forms[i].elements[j];
    if (target.value!='') {
    cible.fireEvent("onchange");
    cible.fireEvent("onfocus");
    cible.fireEvent("onblur");
    if (message!='') {return false;}
    }
    }
    }
    }
    }
    }
    Last edited by jfgabarren; 11-27-2002 at 05:57 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Note: The use of document.all (as he said) is proprietary IE scripting, FYI... although this could be easily modified to work cross-browser, I think (I haven't heard of the fireEvent() function)... anyone care to elaborate as I don't have my javascript bible handy (it's at work!)?
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by whammy
    I haven't heard of the fireEvent() function
    Some IE-only method which will invoke whatever event handler specified as the string argument. The W3C DOM2 Events way to do it is:

    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("blur", false, false);

    aReferenceToMyElement.dispatchEvent(evt);

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cool, thanks. I'll look that up someday since I'm so busy learning .net! (hits CTRL+D).

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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