[Javascript] Question: Getting 2 functions to work on 1 onclick event

Cutter Bl cutterbl at hotmail.com
Wed Aug 8 14:58:53 CDT 2001


You have one function, MM_validateForm(), and you adjust the end of the 
script so that it may end like...

if (validate = true){
     SaveForm.Page.value = otherDoc.body.outerHTML;
     SaveForm.submit();
}

Cutter
http://www.falcon-knives.com

The Past is a Memory
The Future a Dream
But Today is a Gift
That's why they call it
The Present


From: "Neal, Craig" <CNeal at dthr.ab.ca>
Reply-To: javascript at LaTech.edu
To: "'javascript at LaTech.edu'" <javascript at LaTech.edu>
Subject: [Javascript] Question: Getting 2 functions to work on 1 onclick 
event
Date: Wed, 8 Aug 2001 09:42:50 -0600

Any idea how I can get 2 functions to work on the same onclick event?

The first function is a modified Dreamweaver validation script which uses
alert to pop up a window with information on which form fields have not been
completed.

If all fields are complete then it returns no alert window.

function MM_validateForm() { //v4.0

var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args[i]);

if (val) { nm=val.name; if ((val=val.value)!="") {

if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail
address.\n';

} else if (test!='R') {

if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

min=test.substring(8,p); max=test.substring(p+1);

if (val<min || max<val) errors+='- '+nm+' must contain a number between
'+min+' and '+max+'.\n';

} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

} if (errors) alert('The following error(s) occurred:\n'+errors);

document.MM_returnValue = (errors == '');

}

The second function submits the form information for processing to another
page I have.

function Save_onclick() {

SaveForm.Page.value = otherDoc.body.outerHTML;

SaveForm.submit();

}

Both functions work flawlessly by themselves.

However I want MM_validateForm() to be processed first and if it returns no
errors then I want Save_onclick() to run.

This only runs Save_onclick() and never gets to MM_validateForm()

<input type="button" value="Submit Bulletin" name="Save"
LANGUAGE="javascript"

onclick="return
Save_onclick();MM_validateForm('ndate','','R','title','','R','printdate','',
'R','email','','R','moreinfo','','R');return document.MM_returnValue">

and this only runs MM_validateForm() but doesn't run Save_onclick even if
MM_validateForm returns no errors.

<input type="button" value="Submit Bulletin" name="Save"
LANGUAGE="javascript"

onclick="MM_validateForm('ndate','','R','title','','R','printdate','','R','e
mail','','R','moreinfo','','R');return document.MM_returnValue;return
Save_onclick()">

I appreciate any assistance on how I write the syntax so that
MM_validateForm() runs first and if no error messages are generated then
Save_onclick() runs.

Thanks so much.



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list