View Full Version : Ignore 'CC' field in Form Post if left 'blank'
I'd like to give the user an option of specifying a value for a 'cc' email address on a form.
What I'd like to do is to be able to see if a value has been entered into this field. If it is blank then I need the code to ignore the 'cc' declaration.
I cannot change the mail.asp we're using - if I declare the cc field and submit a blank then this generates a error email (and grief for me!:rolleyes: )
Can anyone help please?
Thanks in advance,
N.
jscheuer1
06-01-2006, 06:39 AM
Can you do a:
if (cc!=='')
code here to declare the cc field
Where cc is the value of a text input where the user enters the cc addresses if desired.
So, given that I'm using "mailto" and "mailcc" as the two holders, would it look something like this:
-----------------------------------------------------------
<form name="example" method="post" action="/lib/common/mailing.asp">
<input type="text" name="cc">
<input type="hidden" name="mailto" value="my.usual@email.co.uk">
if (cc!=='') <input type="hidden" name="mailcc" value="cc">
... << the main form elements here >> ...
<input type="Submit" value="Submit">
-----------------------------------------------------------
I am not familiar with the use of IF statements within HTML yet (this will help me learn!) but I'm sure I'm not doing this right! Do I need to enclose the overall statement in brackets or something?
Thanks again for your help,
N.
jscheuer1
06-01-2006, 06:06 PM
If cannot generally be used in HTML (with specific exceptions, this not being one of them). It can generally be used in javascript, try this:
<form name="example" method="post" action="/lib/common/mailing.asp">
<script type="text/javascript">
function createCC(el){
if (el.value!==''&&!document.getElementById('cctestid')){
var theCC=document.createElement('input');
theCC.name='mailcc';
theCC.value=el.value;
theCC.type='hidden';
theCC.id='cctestid';
el.parentNode.appendChild(theCC);
}
else if (el.value!=='')
document.getElementById('cctestid').value=el.value;
else if (document.getElementById('cctestid'))
document.getElementById('cctestid').parentNode.removeChild(document.getElementById('cctestid'));
}
</script>
<input type="text" name="cc" onchange="createCC(this);">
<input type="hidden" name="mailto" value="my.usual@email.co.uk">
... << the main form elements here >> ...
<input type="Submit" value="Submit">
That works just fine!! :)
Thanks for the help on this one - really useful !!
Cheers,
N.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.