Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can display objects ? 3 22
Angular - break the dataset in chunks? 7 39
jquery conditionally populate list boxes 2 22
Having problem getting this to work 2 18
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

21 Experts available now in Live!

Get 1:1 Help Now