...

Validating a form by firing events

jfgabarren
11-27-2002, 05:43 PM
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;}
}
}
}
}
}
}

whammy
12-06-2002, 01:25 AM
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!)?

jkd
12-06-2002, 01:36 AM
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);

whammy
12-06-2002, 01:38 AM
Cool, thanks. I'll look that up someday since I'm so busy learning .net! (hits CTRL+D).

:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum