Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining if-then with mail forms

Status
Not open for further replies.

Breezeman

IS-IT--Management
Dec 12, 2001
125
US
I have a form with checkboxes with unique names and which get the valua Y when checked.

I want to send a seperate, different email for each box checked.

Then on the page after pressing submit, I have added:

<script language=&quot;javascript&quot;
if (PRODUCT1== &quot;Y&quot;)<input type=&quot;hidden&quot; name=&quot;cgiemail_message&quot; value=&quot;message1.txt&quot;>;

if (PRODUCT2== &quot;Y&quot;)<input type=&quot;hidden&quot; name=&quot;cgiemail_message&quot; value=&quot;message2.txt&quot;>;
</script>

So I think it should send message1 when PRODUCT1 has the valua Y, and message2 when PRODUCT2 has the value Y.

But this won't work. Anyone know why? The form I am testing is on
 
You can't embed HTML tags directly. This won't work...

Code:
<script language=&quot;javascript&quot; 
 if (PRODUCT1== &quot;Y&quot;)<input type=&quot;hidden&quot; name=&quot;cgiemail_message&quot; value=&quot;message1.txt&quot;>;
 if (PRODUCT2== &quot;Y&quot;)<input type=&quot;hidden&quot; name=&quot;cgiemail_message&quot; value=&quot;message2.txt&quot;>; 
</script>

Add a document.write statement...
Code:
<script language=&quot;javascript&quot; 
 if (PRODUCT1== &quot;Y&quot;) document.write(&quot;<input type='hidden' name='cgiemail_message' value='message1.txt'>&quot;);
 if (PRODUCT2== &quot;Y&quot;) document.write(&quot;<input type='hidden' name='cgiemail_message' value='message2.txt'>&quot;); 
</script>

But even this probably won't work because of HTML restreaming. A better bet is...
Code:
<html>
<form id=frmForm name=frmForm>
<input id=&quot;hdnMessage&quot; type=&quot;hidden&quot; name=&quot;cgiemail_message&quot; value=&quot;&quot;>
<input type=&quot;checkbox&quot; id=&quot;PRODUCT1&quot; name=&quot;PRODUCT1&quot; value=&quot;Y&quot;>Item #1<br>
<input type=&quot;checkbox&quot; id=&quot;PRODUCT2&quot; name=&quot;PRODUCT2&quot; value=&quot;Y&quot;>Item #2<br>
<br>
<input type=button onClick=&quot;fnSend()&quot; value=&quot;SEND&quot;>
</form>
<script language=&quot;javascript&quot;>
 function fnSend(){
 var z=document.forms.frmForm
 if (z.PRODUCT1.checked) z.hdnMessage.value=&quot;Message1.txt&quot;;
 if (z.PRODUCT2.checked) z.hdnMessage.value=&quot;Message2.txt&quot;;
 alert(z.hdnMessage.value);
 }
</script>

But even that won't work as well as it could. What if both boxes are checked? Either use radio buttons (z.radProduct[0,1,2,3...].checked) or allow for multiple check boxes being used ( if (z.PRODUCT1.checked && z.PRODUCT2.checked) {do something} )

Hope this helps,
Rob


[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top