I have created a function called “validate” to validate that the fields are not left blank and am calling that function in the <form> tag with the onsubmit command, but that doesnt work for some reason.
On my form, I am trying to code it where the user can select a subject to send with the email (it is not showing up in the email). I am also trying to set the email address that the form passes to the cgi script I am using (similar to Matt Wright’s FormMail) to a variable so it can change each time the subject changes and send the email to the person who deals with that particular issue. I want this to be done from where my <Select> tag options change as the user selects a subject on the form. I had If statements on it trying to set the email address, but I took that off, I didn’t have a command to use, I was just trying to set the input tag to each address. The input tag that sets the value of the email address to pass to the cgi is at the bottom of the form code.
(<input type=hidden name=”recipient” value=”
The formmail.cgi script I am using requires the passing of the “recipient” variable as the email address that will receive the email. The cgi script on the server wont send the email if this is not set.
Here is my code:
<style type=”text/css”>
</style>
<Script language=”JavaScript” type=”text/javascript”>
function validate ()
{
if (document.myform.subject.value = “”)
{
alert(‘You must select a subject’);
return false;
}
else if (document.myform.yourname.value = “”)
{
alert(‘Name cannot be blank’);
return false;
}
else if (document.myform.email.value = “”)
{
alert(‘Your email address is required’);
return false;
}
else if (document.myform.Question.value = “”)
{
alert(‘You left the question box blank? Did you have a question?’);
return false;
}
return true;
}
//–>
</Script>
</HEAD>
<BODY>
<BR><BR><BR>
<FORM name=”myform” id=”myform” ACTION=”/cgi-sys/FormMail.cgi” METHOD=”POST”
onsubmit=”return validate ()”>
<table align=”center” border=”2″ cellpadding=”10″ frame=”box” rules=”none”>
<tr>
<td>Your Name </td>
<td>
<INPUT TYPE=”text” size=”30″ name=”yourname” />
</td>
</tr>
<tr>
<td> Your e-mail address </td>
<td>
<INPUT TYPE=”text” size=”20″ NAME=”email” />
</td</tr>
<tr>
<td> Subject </td>
<td>
<Select name = “subject” id=”subject”>
<option value=””> Please select one… </option>
<option value=”1″> Biblical Inquiry </option>
<option value=”2″> Benevolence Inquiry </option>
<option value=”3″> Website Inquiry </select> </option>
</select>
</td></tr>
<tr>
<td> Question </td>
<td>
<textarea name=”question” cols=”40″ rows=”10″>
</textarea> </td></tr>
<tr align=”center”>
<td colspan=”2″>
<hr width=”100% align=”center”> </td></tr>
<tr>
<td colspan=”2″>
<INPUT TYPE= submit value=”Submit Question” />
<input type= reset value=”Reset Form” />
</td> </tr>
</table>
<input type=hidden name=”recipient” value=”
<input type=hidden name=”env_report” value=”REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT”>
</FORM>