post key from array into value upon submit
sLe2222 May 13, 2011 5:17 PMHello,
I am new to ColdFusion and new to this forum, so be kind please. I have a form the gets a select list from an array and I need the key of the array to post into another hidden field upon submission of the form. I have some javaScript validation before the array, so maybe I could include something there, but I just can't figure it out. This is what I have so far:
<script language="javascript" type="text/javascript">
<!--
function OnButton1()
{
var x=document.forms["Form1"]["name"].value
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
var x=document.forms["Form1"]["email"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
var x=document.forms["Form1"]["message"].value
if (x==null || x=="")
{
alert("Message must be filled out");
return false;
}
else
document.Form1.action = "http://fp1.formmail.com/...." // First target
document.Form1.target = "iframe1";
document.Form1.submit(); // Submit the page
document.Form1.action = "contact_us_ty.cfm" // Second target
document.Form1.target = "contact_us_ty.cfm";
document.Form1.submit(); // Submit the page
return true;
}
-->
</script>
<cfset subject[1] = "Choose Subject or Recipient" />
<cfset subject[2] = "Alexis de Tocqueville Society" />
<cfset subject[3] = "Campaign" />
<cfset subject[4] = "Donations" />
<cfset subject[5] = "Feedback" />
<cfset subject[6] = "Getting Help" />
<cfset subject[7] = "Planned Giving" />
<cfset subject[8] = "UW Community Fund" />
<html>
<head></head>
<body>
<form name="Form1" action="contact_us_ty" method="post">
<input type="hidden" name="_pid" value="0" />
<input type="hidden" name="_fid" value="0" />
<input type="hidden" name="recipient" value= "NEED THE KEY HERE" />
<input type="hidden" name="subject" value= "Website Contact Us Email" />
<table width="*" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="2">
<tr valign="middle">
<td align="right"><strong>Name: </strong></td>
<td><input type="text" name="name" size="30" value="" /></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Email Address: </strong></td>
<td><input type="text" name="email" size="30" value="" /></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Subject: </strong></td>
<td>
<select name="subject" id="subject"><cfloop array="#subject#" index="i"><cfoutput><option>#i#</option></cfoutput></cfloop> </select>
</td>
</tr>
<tr valign="top">
<td align="right"><strong>Message: </strong></td>
<td><textarea cols="30" rows="8" name="message"></textarea></td>
</tr>
<tr valign="top">
<td> </td>
<td align="left"><input type="submit" name="button1" value="Submit" onclick="return OnButton1();" /></td>
</tr>
</table>
</form>
<div style="visibility:hidden"><iframe name="iframe1" width="40" height="40"></iframe></div>
</body>
</html>
Any help is greatly appreciated.
Thanks,
sLe2222

