• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

post key from array into value upon submit

Guest
May 13, 2011 May 13, 2011

Copy link to clipboard

Copied

Hello,

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

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 16, 2011 May 16, 2011

Copy link to clipboard

Copied

LATEST

Hi,

1).  I'm assuming that you're naming the select, and passing the array value in the value field.

2).  On the posting page, you should be able to obtain that value.

3).  If you want to then move it into a hidden field, I'd make sure the hidden tag is inside a form tag group, and around that, I'd place <cfoutput> tags.  The value in the hidden tag that you'll want to set to should be inside of #...#.

So page 1: (I'm using input, you should use select)

<form action="two.cfm" method="get">
    <input name="bill" type="text" value="8">
     <input type="submit" value="go">
</form>

Page 2:

<cfoutput>#bill#</cfoutput>

<cfoutput>
<form action="three.cfm" method="get">
    <input name="newbill" type="hidden" value="#bill#">
    <input type="submit" value="go">
</form>
</cfoutput>

Page 3:

<cfoutput>#newbill#</cfoutput>

If you're going to be using this field many times, I'd sugges setting the value equal to a SESSION.variable.  That way you can eliminate all of the hidden tags, which can get really out of hand, and are VERY hard to debug.

something like:  <cfset SESSION.newbill = bill />   Then anytime you need the value, just call the SESSION.newbill.  You would do this on page 2.

Hope this helps,

<cfwild />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation