Binding data to a hidden field before form submission

I have a coldfusion application using a Javascript and a CFFORM that I am having a problem with. The CFFORM tag basically renders as a regular old HTML tag at runtime so don't let it scare you.  It just allows some added flexibility to the form that I need.  

The example below is a stripped down version of what I need, but am using it to test the JavaScript’s.  I am using an online editor and I need to grab the contents of the editor and bind it to a form field.  I have everything I need in terms of functions but I can't get it work.  The exmaple is below.  If I attach the JavaScript which is currently attached to the submit button to a href link, it populates the form field perfectly, so I know I know the JavaScript’s work.  The issue is setting the value of the hidden field before the form gets submitted.  Any suggestions?  Its worth 500 points case I'm desperate.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><cfoutput>#Request.PageTitle#</cfoutput></title>
<title>Submit An announcement</title>
<link href="../common/css/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function retrieveDocument(src){
document.addcontent.contentbody2.value = src;
}
</script>

</head>
<body>
<cfform action="#CurrentPage#" method="post" name="addcontent" preloader="no" id="addcontent">
  <table width="100%" align="center" cellpadding="5">
    <tr valign="baseline">
      <td class="ContentBox-Form-Labels"> Date:</td>
      <td width="460" valign="baseline"><cfinput type="text" name="ContentDate" message="wrong" required="yes" id="ContentDate" size="10" maxlength="10">      </td>
    </tr>
    <tr valign="baseline">
      <td class="ContentBox-Form-Labels">Body:</td>
      <td valign="baseline">
        <cfset configpath="#application.homepath#common\XMLConfigs\Content.xml">
        <cffile action="read" file="#configpath#" variable="xmlConfig">
        <script src="../common/editlivejava/editlivejava.js"></script>
        <cfoutput>
          <script language="JavaScript">
var ELJApplet1_js;
ELJApplet1_js = new EditLiveJava("ContentBody", "700", "300");

ELJApplet1_js.setDownloadDirectory("../common/editlivejava");
ELJApplet1_js.setConfigurationText("#URLEncodedFormat(xmlConfig)#");
ELJApplet1_js.setBody(" ");
ELJApplet1_js.setLocalDeployment(false);
ELJApplet1_js.setAutoSubmit(false);
ELJApplet1_js.setDebugLevel("info");
ELJApplet1_js.setReturnBodyOnly("true");
ELJApplet1_js.setShowSystemRequirementsError(true);
ELJApplet1_js.show();
</script>
        </cfoutput> </td>
    </tr>
    <tr valign="baseline">
      <td class="ContentBox-Form-Labels">&nbsp;</td>
      <td valign="baseline">
        <input type="hidden" name="contentbody2"  id="contentbody2">
               </td>
    </tr>
    <tr valign="baseline">
      <td width="100" class="ContentBox-Form-Labels">&nbsp;</td>
      <td valign="baseline">
        <input type="hidden" name="MM_InsertRecord" value="AddContent">
        
        <input type="submit" name="Submit" value="Submit" onClick="ELJApplet1_js.GetBody('retrieveDocument',true);document.addcontent.submit()"></td>
    </tr>
  </table>
</cfform>
</body>
</html>
SiriusPhilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
Best would be to add your javascript command which you succesfully tested in the a href link, to your form onsubmit action. Not sure how this is done in coldfusion though.

Can you just have something like below?

<cfform action="#CurrentPage#" method="post" name="addcontent" preloader="no" id="addcontent" onsubmit="..copy editor contents to hidden form field..">

-r-
SiriusPhilAuthor Commented:
I actually did that.  I created a function called getbody then called the function using the onsubmit of the form.  I also changed the hidden field to a text field so that I could see what is happening.  The text from the editor does get set in the text field, but the field show empty on the submission page.  So it seems that the field is not getting set before the form submits.

<script language="JavaScript">
function retrieveDocument(src){
document.addcontent.contentbody2.value = src;
}
function getbody()
{
ELJApplet1_js.GetBody('retrieveDocument',true);
}
</script>

and

<cfform action="#CurrentPage#" method="post" name="addcontent" preloader="no" id="addcontent" onsubmit="getbody()">

T
RoonaanCommented:
that's odd. Can you try this:

function getbody(frm)
{
  ELJApplet1_js.GetBody('retrieveDocument',true);
  alert(frm.contentbody2.value);
  frm.submit();
  return false;
}

<cfform action="#CurrentPage#" method="post" name="addcontent" preloader="no" id="addcontent" onsubmit="return getbody(this)">

-r-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

SiriusPhilAuthor Commented:
With the alert, the function runs fine.  When I click out of the alert, the form submits as expected.  Looks like I need to add some type of delay?
SiriusPhilAuthor Commented:
Fixed it.  The final function looks like this:

<script language="JavaScript">
function retrieveDocument(src){
document.addcontent.contentbody.value = src;
}
function getbody(form)
{
  ELJApplet1_js.GetBody('retrieveDocument',true);
  setTimeout('document.addcontent.submit();', 500);
  return false;
}
</script>
SiriusPhilAuthor Commented:
Thanks.  Works like a charm thanks to you.  Now have a seperate question on how to make the functions dynamic.  Will post a another question for it though.

Phil Hayes
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.