Skip navigation
Currently Being Moderated

post key from array into value upon submit

May 13, 2011 5:17 PM



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;
    document.Form1.action = ""    // First target = "iframe1";


    document.Form1.submit();        // Submit the page
    document.Form1.action = "contact_us_ty.cfm"    // Second target = "contact_us_ty.cfm";


    document.Form1.submit();        // Submit the page
    return true;
<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" />




        <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 valign="middle">
                      <td align="right"><strong>Email Address: </strong></td>
                      <td><input type="text" name="email" size="30" value="" /></td>
                <tr valign="middle">
                      <td align="right"><strong>Subject: </strong></td>
                        <select name="subject" id="subject"><cfloop array="#subject#" index="i"><cfoutput><option>#i#</option></cfoutput></cfloop>       </select>
                <tr valign="top">
                      <td align="right"><strong>Message: </strong></td>
                      <td><textarea cols="30" rows="8" name="message"></textarea></td>
                <tr valign="top">
                  <td> </td>
                  <td align="left"><input type="submit" name="button1" value="Submit" onclick="return OnButton1();" /></td>

<div style="visibility:hidden"><iframe name="iframe1" width="40" height="40"></iframe></div>



Any help is greatly appreciated.



  • Currently Being Moderated
    May 16, 2011 7:11 PM   in reply to sLe2222



    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">


    Page 2:




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


    Page 3:




    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 />

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points