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

Appending form field value to hidden field value

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
OK, I have a form that posts to a mail script. In that form, there is a hidden field called recipient and (among other things) a field called Email. What I need to do is append that form field onto the hidden field when the form is submitted. So...
Code:
<form action="/scripts/email.asp" method="post" name="form1">
<input type="hidden" name="recipient" value="email@email.com">
<input type="text" name="email" value="">
</form>
and I was thinking something like
Code:
<script type="text/javascript">
function addRecipient()
{
document.getElementById('Recipient').value += ";" + document.getElementById('Email').value
return true
}
</script>

I know this isn't quite right, but I am stumped, so any help you folks can give me would be greatly appreciated. Oh, and what I need to end up with is something like

Code:
<form action="/scripts/email.asp" method="post" name="form1">
<input type="hidden" name="recipient" value="email@email.com;email2@email.com">
<input type="text" name="email" value="">
</form>

Where the email addresses in the hidden field are separated by a semi-colon.

Willie
 
try:
Code:
<input type="hidden" name="recipient" [COLOR=red]id="Recipient"[/color] value="email@email.com;email2@email.com">
<input type="text" name="email" [COLOR=red]id="email"[/color] value="">



Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Thanks, but really what I need is for the value that is entered into the form field "Email" to be appended onto the hidden field "Recipient", so if the hardcoded value is email@email.com and the user enters me@email.com, what gets sent in the recipient field is "email@email.com;me@email.com". Is that more clear? Sorry about my earlier example.

Willie
 
Your using the getElementById function to get the elements valuse but your elements don't have ID's. Also, javascript is case sensitive. Clear those issues up and you should be able to get it.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Ahh... got it. Thanks, I will give those changes a shot!
 
OK, I am likely making some fairly obvious mistake, so here is my code

Code:
<script type="text/javascript"> 
function addRecipient() 
{ 
 document.form1.getelementById('recipient').value += "willieb@laplink.com;" + document.form1.getelementById('email').value 

 return true 
}
</script>

Code:
<FORM ACTION="/scripts/email.asp" METHOD="POST" id=form1 name=form1 onSubmit="return addRecipient()">
		<input type="hidden" name="recipient" id="recipient" value="willie@test.com">
		<input type="hidden" name="address" value="<%= RS("Address") %>">
		<center>
		<table border=0 cellpadding=0 cellspacing=0>
		<tr><td align=right><font face="Arial,Helvetica,sans-serif"><b>Name: </b></font></td><td colspan=2><INPUT TYPE="text" NAME="name" VALUE="" SIZE=30  ></td></tr>
		<tr><td align=right><font face="Arial,Helvetica,sans-serif"><b>Email address: </b></font></td><td colspan=2><INPUT TYPE="text" NAME="email" ID="email" VALUE="" SIZE=30  ></td></tr>
.
.
.

This will always be just 2 email addresses, the one hard coded and one from the form. My attempt above still only sends the hard coded recipient value and does not seem to append the form value.

Willie
 
1. The function "getelementById" should be getElementById.
2. Your form element need quotes around the values for the Id and name parameters.


Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Additionally the form object does not have a getElementById function either. Remove the "form1" part from your getElementById calls.

In other words this:

Code:
document.[red]form1[/red].getelementById('recipient').value += "willieb@laplink.com;" + document.[red]form1[/red].getelementById('email').value

Should be:

Code:
document.getelementById('recipient').value += "willieb@laplink.com;" + document.getelementById('email').value

With that said, most of these errors should be easily debugged if you use the browser's error reporting tools. both IE and FF have ways of seeing any errors your JS may be generating.

IE offers the yellow shield at the bottom left corner of the browser window, that when double clicked will show the errors.

FF has its Error console.

Use them when debugging.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top