Solved

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

Posted on 2008-10-18
5
189 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
[X]
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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 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