/    Sign up×
Community /Pin to ProfileBookmark

HTML/JavaScript with a Form Passing variable problem. Please Help!

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=”[email protected]“> )

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” /> &nbsp;
<input type= reset value=”Reset Form” />
</td> </tr>

</table>

<input type=hidden name=”recipient” value=”[email protected]“>

<input type=hidden name=”env_report” value=”REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT”>

</FORM>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@TageSep 18.2004 — your conditional if statements are using single equal signs (=), they need to be double equal signs (==).

Tage
Copy linkTweet thisAlerts:
@AllonschauthorSep 18.2004 — Which statements are you talking about? The ones in my <Select> statements (The options)?
Copy linkTweet thisAlerts:
@TageSep 18.2004 — [b]if (document.myform.subject.value = "")[/b]
{
alert('You must select a subject');
return false;
}
[b]else if (document.myform.yourname.value = "")[/b]
{
alert('Name cannot be blank');
return false;
}
[b]else if (document.myform.email.value = "")[/b]
{
alert('Your email address is required');
return false;
}
[b]else if (document.myform.Question.value = "")[/b]
{
alert('You left the question box blank? Did you have a question?');
return false;
}
return true;
Tage
Copy linkTweet thisAlerts:
@AllonschauthorSep 18.2004 — I figured it out on that part. Thanks for the help. Do you have any idea about the subject variable passing it to the script so it will route the email to different addresses for different subjects?
Copy linkTweet thisAlerts:
@TageSep 18.2004 — That should probably be handled with the server-side script.

Tage
Copy linkTweet thisAlerts:
@AllonschauthorSep 18.2004 — Thanks for your help, but I cant edit the server side script. It is supplied by my webhosting company. I just link to it. You can see the properties of it by going to this link:

http://www.scriptarchive.com/readme/formmail.html#necessary_form_fields

However, I cant edit it. And I wouldn't know where to start if I could. I just thought there had to be a way to pass a variable to that script through html/javascript.
×

Success!

Help @Allonsch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...