Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello I got an assignment and I can't figure out how to send email based on the fields.

So for example I have four text fields: title, first/last name and email.
Then a button "confirm". When the button is pressed it will run the script.

I got the script running but only with fixed data, which is not quite what is required.

Thanks in advance!

This is my script:
XML
<script>
function sendEmail()
/* This script by pressing "Confirm" will automatically open a default email software to send email to the address
provided with subject "Assignment4" and body from the input fields.
*/
{
    window.open('mailto:test@example.com?subject=Assignment4&body=SUSHI-MASTER James Tam');
}
</script>
Posted
Updated 14-Apr-15 11:12am
v2
Comments
Sergey Alexandrovich Kryukov 14-Apr-15 17:40pm    
What is that supposed to mean: sending e-mail from HTML to JavaScript? I guess, you are sending it to test@example.com. Anyway, JavaScript doesn't send mail.
If what you are doing is what you want, not clear what prevents you from using a variable string instead of constant.
Note that the whole thing makes very little sense: if your user is supposed to type title, name and all of that, why not doing it in some appropriate mail client?
—SA

1 solution

1. Create a form with textboxes as you have mentioned

2.
XML
Hide   Copy Code
<script>
function sendEmail()
/* This script by pressing "Confirm" will automatically open a default email software to send email to the address
provided with subject "Assignment4" and body from the input fields.
*/
{

window.open('mailto:'+document.getElementById ( " txtMailToId").value+'?subject='+document.getElementById ( " txtTitle").value+'4&body='+document.getElementById ( " txtFirstName").value+" " + document.getElementById ( " txtLastName").value);
}
</script>
 
Share this answer
 
Comments
Member 11607592 14-Apr-15 20:04pm    
Thanks a lot! If you don't mind I have one more question..
There is an extra marks for a script that will check if all four fields are not empty to be able to send email.

Thanks again.
ramyajaya 14-Apr-15 20:14pm    
mailto= document.getElementById ("txtMailToId");

If ((mailto!="")&&(//other conditions))
{
//do other functions
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900