kudos said:
I want to set up an e-mail form containing information that visitors
may send to their friends, that is, they write their friends e-mail
address on the form and click submit.
This code should work.
I think the only proviso is that the sender must have a default email client
Also note that the number of recipients is hard coded (as 4). This could
benefit from some tweaking, so that the functions determine how many there
are. In fact it must be exactly 4, which is also a drawback.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<!-- formtest.html -->
<head>
<title>Form Test</title>
<meta name="Author" content="Trevor Lawrence"/>
<meta http-equiv="Content-Language" content="en-au"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Internal JS -->
<script type="text/javascript">
function checkEmailAddress(field)
{
// the following expression in () after 'match' must be all on one line...
if
(field.value.match(/(^(\S+@)\S+(((\.ac)|(\.aero)|(\.arpa)|(\.biz)|(\.co)|(\.com)|(\.coop)|(\.edu)|(\.firm)|(\.gov)|(\.info)|(\.int)|(\.jobs)|(\.mil)|(\.museum)|(\.name)|(\.nom)|(\.net)|(\.org)|(\.pro)|(\.store)|(\.travel)|(\.web))(\.\S{2})?)$)/i))
return true
else
{ alert('Please enter a valid e-mail address.')
field.focus()
field.select()
return false }
}
// --------------------
function testform()
{
with (document.form1)
{
for (var i = 1; i <= 4 ; i++)
if (!checkEmailAddress(elements['Email' + i]))
return
}
}
// --------------------
function sendform()
{
var recpt = ''
for (var i = 1; i <= 4 ; i++)
{
recpt += document.form1.elements['Email' + i].value
if (i < 4 )
recpt += ';'
}
with (document.form1)
{
var body = ''
var i = elements.length , j = 0
while (i-- > 2) // drop last two elements
{
var tname = elements[j].id
var text = elements[j].value
if (!tname.match(/(^Email)/))
{ body += text }
j += 1
} // end while
}
window.location = "mailto:" + recpt
+ "?subject=Response%20from%20Form1"
+ "&body=" + body
}
// --------------------
</script>
</head>
<!-- ================================================ -->
<body onload="">
<noscript>
This site requires Javascript enabled<br />
</noscript>
<div id="maindiv" align="center">
<div style="border:1px solid #999999; width:60%;
background-color:#F2F4FA;">
<form name="form1" action="">
<div style="background-color:#DBE0F5; padding:3px; font:75% arial;">
<b>Send this information to 4 friends</b>
</div>
<div style="padding:10px; font:75% Arial; text-align:left;">
<p>
Email1:<br/>
<input type="text" id="Email1" value="Insert e-mail address" size="40"
onfocus="if (this.value=='Insert e-mail
address'){this.value='';};return false;"
onblur="if (this.value==''){this.value='Insert e-mail
address';return false;}"/><br/>
Email2:<br/>
<input type="text" id="Email2" value="Insert e-mail address" size="40"
onfocus="if (this.value=='Insert e-mail
address'){this.value='';};return false;"
onblur="if (this.value==''){this.value='Insert e-mail
address';return false;}"/><br/>
Email3:<br/>
<input type="text" id="Email3" value="Insert e-mail address" size="40"
onfocus="if (this.value=='Insert e-mail
address'){this.value='';};return false;"
onblur="if (this.value==''){this.value='Insert e-mail
address';return false;}"/><br/>
Email4:<br/>
<input type="text" id="Email4" value="Insert e-mail address" size="40"
onfocus="if (this.value=='Insert e-mail
address'){this.value='';};return false;"
onblur="if (this.value==''){this.value='Insert e-mail
address';return false;}"/><br/>
</p>
Enter Text in here:<br/>
<textarea rows="10" cols="100"
style="font:100% Arial;">Enter your text in
here</textarea><br />
</div>
<div align="center" style="background-color:#DBE0F5; padding:3px;
font:12px arial;">
<input type="button" id="submit" value=" Send "
onmouseover="testform()" onclick="sendform()" />
<input type="reset" id="reset" value=" Clear "/>
</div>
</form>
</div>
</div> <!-- end id="maindiv" -->
</body>
</html>