JavaScript question
Posted: 2007-06-10 06:00pm
I've been trying to write a JavaScript form that will thwart bots that crawl the site to harvest email addresses. I rather thought that what I've written should work, but nothing happens when I click the send button. Can somebody check my code?
Code: Select all
<html>
<head>
<script language="JavaScript">
<!--
/* BOT-RESISTANT EMAIL GENERATOR
Ted Collins, 2007 */
/* Uses code from The JavaScript Source!! http://javascript.internet.com
Created by: CodeLifter.com | http://www.codelifter.com */
// DECLARE VARIABLES
var email_name, email_service, eAddress, eSubject, office_name, office_num;
// BUILD EMAIL
function sendMail()
{
//BUILD ADDRESS
switch (document.mail_form.officer_select.value)
{
case 1: // Seneschal
email_name = "address.one";
email_service = "comcast.net";
break;
case 2: // Knight Marshal
email_name = "address.two";
email_service = "comcast.net";
break;
case 3: // A&S Minister
email_name = "address.three";
email_service = "comcast.net";
break;
case 4: // Chatelaine
email_name = "address.four";
email_service = "comcast.net";
break;
case 5: // Herald
email_name = "address.five";
email_service = "comcast.net";
break;
case 6: // Reeve
email_name = "address.six";
email_service = "hotmail.com";
break;
default: // Seneschal
email_name = "address.one";
email_service = "comcast.net";
break;
}
eAddress = email_name + "@" + email_service;
// BUILD SUBJECT LINE
if (mail_form.subj.value==null)
{
eSubject = "?subject=" + mail_form.subj.value;
}
else
{
eSubject = "?subject=No subject";
}
// BUILD MESSAGE BODY
if (mail_form.subj.value==null)
{
eBody = "&body=" + mail_form.bod.value";
}
else
{
eBody = "&body=No message";
}
// OPEN EMAIL
document.location = "mailto:" + eAddress + eSubject + eBody;
}
//-->
</script>
</head>
<body>
<h2>Contact</h2>
<p>Use the following form to send a message to a Shire officer.</p>
<!-- BOT-RESISTANT EMAIL FORM -->
<form id="mail_form" name="mail_form">
<table>
<tr>
<td>Email to:</td>
<td><SELECT size="1" id="officer_select" name="officer_select">
<OPTION value=1 selected>Seneschal</OPTION>
<OPTION value=2>Knight Marshal</OPTION>
<OPTION value=3>A&S Minister</OPTION>
<OPTION value=4>Chatelaine</OPTION>
<OPTION value=5>Herald</OPTION>
<OPTION value=6>Reeve</OPTION>
</SELECT></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subj" size="40" value="Subject"></td>
</tr>
<tr>
<td>Content:</td>
<td><input type="text" name="bod" size="40" value="Your question"></td>
</tr>
<tr>
<td> </td>
<td><input type="button" value="Send" onclick="sendMail()">
<input type="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>