Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-10-18
5
186 Views
Last Modified: 2013-11-19
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?
0
Comment
Question by:rayskelton
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22750235

<form name="myResumeForm" onSubmit="return isValidData()" action="mailto:sskelton@bellsouth.net" method="post">
<input type="submit"/>
</form>
 
<script>
function isValidData(){
if(true) //it's good
	return true;
else //no good don't mail
return false; 
}
</script>

Open in new window

0
 

Author Comment

by:rayskelton
ID: 22750502
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.
0
 
LVL 16

Expert Comment

by:sh0e
ID: 22750687
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

0
 
LVL 16

Expert Comment

by:sh0e
ID: 22750776
I think it might help if you post more code, or preferably a demo.
0
 

Author Closing Comment

by:rayskelton
ID: 31507493
This works great. Thanks for your help
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question