Link to home
Start Free TrialLog in
Avatar of rayskelton
rayskelton

asked on

For HTML forms, How do I validation through JavaScript and email form?

For HTML forms, How do I validation through JavaScript and email form? I can validate the form successfully through JavaScript and can also email the form but not both. Is this possible?

This works
<form name="myForm" onSubmit="return isValidData(firstname, lastname, email)" >

This works
<form name="myResumeForm" action="mailto:sskelton@bellsouth.net" method="post">

How do I combine the two to validate the form and then email the form?
ASKER CERTIFIED SOLUTION
Avatar of sh0e
sh0e

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rayskelton
rayskelton

ASKER

This submits the form to my email but does not halt in field validation errors. I would like to run the js and validate the form before sending the email. If validation fails, no email is sent.

This sends email, regardless of field validation
<form name="myForm" onSubmit="return isValidData()" action="mailto:abc@bellsouth.net" method="post">



I need to only send email if the field validation returns false.
Are you sure?
If isValidData() returns false, it should halt execution.
Try the below code.
<form name="myResumeForm" onSubmit="return isValidData()" action="mailto:sskelton@bellsouth.net" method="post">
<input type="button" onclick="setValid();" value="Toggle isValidData()"/>
<input type="submit"/>
</form>
 
<script>
var isValid = false;
function setValid(){
isValid = isValid ? false : true;
}
function isValidData(){
return isValid;
}
</script>

Open in new window

I think it might help if you post more code, or preferably a demo.
This works great. Thanks for your help