R
RobG
I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.
I can create a mailto link in the page using innerHTML, but it seems
silly to click a button, a link appears, then click on the link.
How do I execute the mailto command using JavaScript?
And before I get beaten up over using mailto, it's for a simple
intranet application to get the answers to a couple of survey
questions. I know all my users have one of two browsers and the same,
fully configured e-mail client. The alternative is for some MS script
guru to code the thing as a Word macro...yechh
Some play code follows.
Regards, Rob.
<html><head><title>Mail to page</title>
<script type="text/javascript">
function sendValues(f,x) {
var a = f.elements;
var b = "The message:";
for (var i=0; i<a.length; i++) {
if (a.parentNode.nodeName == 'LABEL'){
if (a.type =='textarea' || a.type =='text')
b += writeB(a);
if (a.type =='radio' && a.checked)
b += writeB(a);
}
}
alert(b)
alert(escape(b));
document.getElementById(x).innerHTML = '<a href=\''
+ 'mailto:[email protected]?SUBJECT=E-mail from a form'
+ '&body=' + escape(b) + '\'>Click here to send...</a>';
}
function writeB(x){
return '\n' + x.name + ': ' + x.value;
}
</script>
<style type="text/css">
body {font-family: sans-serif; margin-left: 40;}
input {font-family: sans-serif;}
label {padding-bottom: 40;}
</style>
</head>
<body margin>
<form action="">
<label for="a1">Enter text 1<br>
<input type="text" name="a1"><br>
<label for="a2">Enter text 2<br>
<textarea name="a2" rows="5" cols="30"
wrap="physical"></textarea><br>
<label for="a3">Pick an option
<input type="radio" name="a3" value="none" checked="checked"
style="display: none;"><br>
<input type="radio" name="a3" value="A">Option A<br>
<input type="radio" name="a3" value="B">Option B<br>
<input type="radio" name="a3" value="C">Option C<br>
</label><br>
<input type="reset" value="Clear all entries">
<input type="button" value="Click to submit" onclick="
sendValues(this.form,'xx');
">
</form>
<div id="xx"></div>
</body>
</html>
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.
I can create a mailto link in the page using innerHTML, but it seems
silly to click a button, a link appears, then click on the link.
How do I execute the mailto command using JavaScript?
And before I get beaten up over using mailto, it's for a simple
intranet application to get the answers to a couple of survey
questions. I know all my users have one of two browsers and the same,
fully configured e-mail client. The alternative is for some MS script
guru to code the thing as a Word macro...yechh
Some play code follows.
Regards, Rob.
<html><head><title>Mail to page</title>
<script type="text/javascript">
function sendValues(f,x) {
var a = f.elements;
var b = "The message:";
for (var i=0; i<a.length; i++) {
if (a.parentNode.nodeName == 'LABEL'){
if (a.type =='textarea' || a.type =='text')
b += writeB(a);
if (a.type =='radio' && a.checked)
b += writeB(a);
}
}
alert(b)
alert(escape(b));
document.getElementById(x).innerHTML = '<a href=\''
+ 'mailto:[email protected]?SUBJECT=E-mail from a form'
+ '&body=' + escape(b) + '\'>Click here to send...</a>';
}
function writeB(x){
return '\n' + x.name + ': ' + x.value;
}
</script>
<style type="text/css">
body {font-family: sans-serif; margin-left: 40;}
input {font-family: sans-serif;}
label {padding-bottom: 40;}
</style>
</head>
<body margin>
<form action="">
<label for="a1">Enter text 1<br>
<input type="text" name="a1"><br>
<label for="a2">Enter text 2<br>
<textarea name="a2" rows="5" cols="30"
wrap="physical"></textarea><br>
<label for="a3">Pick an option
<input type="radio" name="a3" value="none" checked="checked"
style="display: none;"><br>
<input type="radio" name="a3" value="A">Option A<br>
<input type="radio" name="a3" value="B">Option B<br>
<input type="radio" name="a3" value="C">Option C<br>
</label><br>
<input type="reset" value="Clear all entries">
<input type="button" value="Click to submit" onclick="
sendValues(this.form,'xx');
">
</form>
<div id="xx"></div>
</body>
</html>