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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CC email recipient in text box

Status
Not open for further replies.

dadms

Technical User
Mar 8, 2003
67
0
0
US
I am having a difficult time figuring this out. I would like to CC a recipient using the mailto function. The recipient would be a manually entered in a text box.

<SCRIPT LANGUAGE="JavaScript">
function IsEmailValid(form1,email)
{
var EmailOk = true
var Temp = document.form1.email
var AtSym = Temp.value.indexOf('@')
var Period = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1 // Array is from 0 to length-1

if ((AtSym < 1) || // '@' cannot be in first position
(Period <= AtSym+1) || // Must be atleast one valid char btwn '@' and '.'
(Period == Length ) || // Must be atleast one valid char after '.'
(Space != -1)) // No empty spaces permitted
{
EmailOk = false
alert('Please enter a valid e-mail address!')
Temp.focus()
}
return EmailOk

alert("Thank your filling out the form.");
return true;

}


</script>

</head>

<body>
<body>
<form method="POST" name="form1" ACTION="mailto:test@comcast.net;document.form1.email.value?cc=test1@comcast.com&subject=LOCAL FORM"
enctype= "text/plain" onSubmit="return IsEmailValid(form1,email);">

<TABLE>
<tr>
<td align="left">EMAIL</td>
<td width="23%"><input type=text name=email size=25 maxlength=50><font size="2" color="#ff0000">*</font></td>
<td width="12%" align="right">&nbsp;</td>
<td width="12%" align="left"><font size="2">EMAIL2</font>
<td width="23%"><input type=text name=memail size=25 maxlength=50><font size="2" color="#ff0000">*</font></td> </tr>
<tr>
<td colspan="5" align="center" style="border-left: 1px solid #000000; border-right: 1px solid #000000; border-top-width: 1px; border-bottom: 1px solid #000000" bgcolor="#E5E5E5">
<p>
<br>
<input type=submit value="Submit Form" onclick=></td>
</tr>

</TABLE>
</body>

</html>


 
I think changing your form line to this:
Code:
<form method="POST" name="form1" ACTION="mailto:test@test.com?subject=local%20form&cc=test1@test.com"
enctype="text/plain" onSubmit="return IsEmailValid(form1,email);">
will do it for you.

Hope that helps

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Im sorry maybe my email was a bit confusing. The form works but I have an email box in the form where people can put their email address.

I would like to use this field to determine the CC address.
Code:
<tr>
    <td align="left">EMAIL</td>
    <td width="23%"><input type=text name=email size=25 maxlength=50><font size="2" color="#ff0000">*</font></td>

what would I have referencee here to make this happen:
Code:
<form method="POST" name="form1" ACTION="mailto:test@comcast.net;document.form1.email.value?cc=test1@comcast.com&subject=LOCAL FORM"
enctype= "text/plain" onSubmit="return IsEmailValid(form1,email);">
 
Sorry about that. Try changing your script to this:
Code:
<SCRIPT type='text/javascript'>
function IsEmailValid(form1,email)
{
var EmailOk  = true
var Temp     = document.form1.email
var AtSym    = Temp.value.indexOf('@')
var Period   = Temp.value.lastIndexOf('.')
var Space    = Temp.value.indexOf(' ')
var Length   = Temp.value.length - 1   // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
      EmailOk = false
      alert('Please enter a valid e-mail address!')
      Temp.focus()
   }
newCC = document.forms["form1"].email.value;
document.forms["form1"].setAttribute("action","mailto:test@comcast.net?subject=LOCAL%20FORM&cc="+newCC);
return EmailOk

alert("Thank your filling out the form.");
return true;

}


</script>

That sends the CC to the value of the first textbox.

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
eledigito,

does
Code:
document.forms["form1"].setAttribute("action","mailto:test@comcast.net?subject=LOCAL%20FORM&cc="+newCC);

take the place of the mailto function in the FORM code.
I tried it with and without the ACTION in the FORM code and it does not seem to work.
 
When I tested it locally, I set the form's action equal to nothing,
Code:
<form action=''>
. That line sets the form's action to mailto, adding the CC address.

Everything worked when I tested it, are u experiencing any specific problems?

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top