Solved

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

Posted on 2008-10-18
5
183 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now