Mailto: subject line populated by form data

Status
Not open for further replies.
I created a basic form with basic text input fields named account, description, date, time, person, title, and contact.

I added a submit button that when clicked would launch my external javascript.
<input type="submit" name="sendEmail" value="Submit Ticket" onclick="SendEmail(this.form)" />

My javascript:
function SendEmail(frm){
var emailAddress="apersonemail@somewhere.com; apersonemail@somewherelese.com;"
var message = "Hello,"+ "\n";
message = message +"\nAlarm Account #: " + frm.account.value + "\n"
+ "\n" + frm.description.value + "\n"
+"\nDate Notified: " + frm.date.value + "\n"
+"Time Notified: " + frm.time.value + "\n"
+"\nNotifying Party: " + frm.person.value + "\n"
+"Title: " + frm.title.value +"\n"
+"Contact Information: " + frm.contact.value + "\n"

document.location.href = "mailto:"+emailAddress+"?subject="+frm.account.value+" Work Order Request "+frm.date.value+"&bcc=aperson@nothere.com&body="+escape(message);
}

When the submit button is clicked, an email is generated with email addresses populated, the body completed with the message var (to include the fields entered in the form: account, description, date, time, person and contact). Subject line is populated with form field values Account and date, separated by my own text of Work Order Request: "?subject="+frm.account.value+" Work Order Request "+frm.date.value+"

This is probably not the easiest or best way to do this, but it works for me.
 
Code:
<script type="text/JavaScript" src="http://www.siue.edu/commencement/commencement_web_site.js" language="JavaScript"><!----></script>
<form onsubmit="return checkFieldsCommencement();window.location='mailto:me@domain.com?subject='+commencementform.name.value" name="commencementform" action="http://www.siue.edu/cgi-bin/FormMail.pl" method="post">
<input name="recipient" type="hidden" value="ddennis@siue.edu" />
<input name="email" type="hidden" value="ddennis@siue.edu" />
<input name="subject" type="hidden" value="Commencement Form" />
<input name="redirect" type="hidden" value="http://www.siue.edu/commencement/acknowledgement.shtml" />

Try this.

This could cause problems with trying to advance to the next step which would be posting the data to Formmail.pl. The problem is caused by redirecting the same window to a new location (web address) so instead we should open a new window with javascript; beware of popup blockers. use window.open(url);

DevGuru JavaScript METHOD: window::eek:pen
 
Don't get any javascript errors. Just doesn't insert what I want into the subject line. It inserts the field name itself instead of the data from the field name.
 
Status
Not open for further replies.
Back
Top Bottom