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

Taking a form field and putting it into email subject line

Status
Not open for further replies.

WAHMom

Programmer
Dec 11, 2002
30
US
Is there a way to take a predetermined form submission field such as "CompanyName" and put it into the subject line of the resulting email? I am using a cgi script but the subject line info is currently coming from a hidden field within my html and is not variable.

Any help is greatly appreciated!
 
change the value of the hidden field to the CompanyName value
<script>
document.formname.hiddenfieldname.value = the company name ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
I had been trying to do that in varying syntax but it wasn't working. Based upon what you suggested I now have:

<script>
document.applicant.COMPANYNAME.value = test
</script>

and this is in the body with the other hidden field info:

<input type=&quot;hidden&quot; name=&quot;subject&quot; value=test>

Whether &quot;test&quot; is in quotes or not the subject line still ends up just being the word test.

I don't know if this should matter or not, but the data is being encrypted when it is submitted.

Am I missing something obvious? Thanks for your help.
 
ok, you have three things here
the companyname field (or hard coded name)
the hidden form field
the script to transfer the name
<script>
document.applicant.subject.value = document.applicant.COMPANYNAME.value
// test it
alert(document.applicant.subject.value);
</script>

<input type=&quot;text&quot; name=&quot;COMPANYNAME&quot;>
<input type=&quot;hidden&quot; name=&quot;subject&quot; value=test>

so to use this we could do something like this
<html>
<head>
<script>
function changeIt() {
document.applicant.subject.value = document.applicant.COMPANYNAME.value
// test it
alert(document.applicant.subject.value);
}
</script>
</head>
<body>
<form name=&quot;applicant&quot;>
<input type=&quot;text&quot; name=&quot;COMPANYNAME&quot;>
<input type=&quot;hidden&quot; name=&quot;subject&quot; value=test>
<input type=&quot;button&quot; value=&quot;do it&quot; onClick=&quot;changeIt()&quot;>
</form>
</body>
</html> ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
The alert you suggested shows that it is working but it is the &quot;value=&quot; part that isn't grabbing the new value. As it is written above, the subject lines shows the word &quot;test&quot;. I don't have &quot;test&quot; defined anywhere so I am sure that is the problem. However, I don't know what to put there. I have tried &quot;document.applicant.subject.value&quot; and &quot;subject&quot; both with and without quotes and I only get that text as the subject.

Sorry to be a pain, but I have been hitting a brick wall with this yet it seems it should be possible.
 
I'm confused. it doesn't matter what is in the value of the hidden field. take it out if you want. the script is dynamicaly changing it.
so if you put in the text box COMPANYNAME
tek tips
the alert will say tek tips because you ahve dynamicaly changed the value that is being held in the hidden field. ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Wullie,
I found how to do that, however I want to take the info from the COMPANYNAME field and move it to the subject line as well as use it for the COMPANYNAME in the body of the email. This just will help us to see at a glance what client the requests are from. Having the client type it twice really isn't an option.

What onpnt suggested above has not worked as far as getting it into the subject line and I have spent the better part of the day and evening struggling with this. If I leave out the hidden subject value and/or line, then I get the generic &quot; Form&quot; subject line which isn't useful either.

Any help is appreciated.
 
Ok, well onpnt's script works just fine for me, I added the action attribute to the form and everything.

If this is being built by a cgi script, there is no real reason to not use the companyname field as the subject line. I'm not sure what the problem is there... or, you could simply set the subject as a text field and then re-use it later in the body of the email...

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Thank you for all of the advice. I don't know why it wasn't working, but I modified the script above and made it work this way:

<script>
function changeIt() {
worthit = document.applicant.COMPANYNAME.value
return worthit;
}
</script>


onclick=&quot;document.applicant.subject.value=changeIt();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top