Skip navigation
saintsilver
Currently Being Moderated

cfform (flash) and javascript integration

May 2, 2007 10:17 AM

I've been searching and shooting in the dark for 2 days and can't get this to work...

I need to have my flash form button execute a javascript, return the value to the form and then I need the form to submit and take advantage of cfform's validation.

So far, I get the javascript to change the value of the form field without submitting the form, but when I add the submit line, the form submits before the javascript returns the changes.

Here is my sample:


<script language="JavaScript" type="text/javascript">
function changeSomething(x,z1,z2)
{
var z3 = "window.document."+z1+ ".SetVariable";
if (x != "ABCDEFG")
{
eval(z3+"(z2+'.text', 'INVALID Name')");
}
}
</script>

<cfsaveContent variable="prevalidateIt">
getURL("javascript:changeSomethig('"+name.text+"','Step1','name')");
submitForm();
</cfsavecontent>

<cfform method="post" name="Step1" preloader="no" format="flash" width="960">

<cfformgroup type="panel" label="Step 1" visible="yes" enabled="yes">
<cfformgroup type="hbox" visible="yes" enabled="yes">
<cfformgroup type="hbox" width="200" visible="yes" enabled="yes">
<cfinput type="text" name="name" size="12" maxlength="11" width="12" label="name" validateat="onSubmit" validate="maxlength" required="yes" />
</cfformgroup>
</cfformgroup>
<cfformgroup type="hbox" visible="yes" enabled="yes">
<cfformgroup type="hbox" visible="yes" enabled="yes">
<cfinput type="button" name="Submit" value="Submit" onclick="#prevalidateIt#" />
</cfformgroup>
<cfformgroup type="hbox" visible="yes" enabled="yes">
<cfinput name="Reset" type="reset" id="Reset" value="Reset" />
</cfformgroup>
</cfformgroup>
</cfformgroup>

</cfform>


My javascript is of course way more complicated than this one and goes through several steps of validation of the form field. It will ultimately be used on multiple fields in the form.

Has anybody else tried to do something similar.

Thanks!


 
Replies
  • Currently Being Moderated
    May 2, 2007 9:23 PM   in reply to saintsilver
    I ran your code. It appears to work as expected. The only major change is that I corrected the typo javascript:changeSomethi ng.

    <script type="text/javascript">
    function changeSomething(x,z1,z2)
    {
    var z3 = "window.document."+z1+ ".SetVariable";
    if (x != "ABCDEFG")
    {
    eval(z3+"(z2+'.text', 'INVALID Name')");
    }
    }
    </script>

    <cfsaveContent variable="prevalidateIt">
    getURL("javascript:changeSomething('"+name.text+"','Step1','name')");
    submitForm();
    </cfsavecontent>

    <cfform method="post" action="#cgi.script_name#" name="Step1" preloader="no" format="flash" width="960">
    <cfformgroup type="panel" label="Step 1" visible="yes" enabled="yes">
    <cfformgroup type="hbox" visible="yes" enabled="yes">
    <cfformgroup type="hbox" width="200" visible="yes" enabled="yes">
    <cfinput type="text" name="name" size="12" maxlength="11" width="12" label="name" validateat="onSubmit" validate="maxlength" required="yes" />
    </cfformgroup>
    </cfformgroup>
    <cfformgroup type="hbox" visible="yes" enabled="yes">
    <cfformgroup type="hbox" visible="yes" enabled="yes">
    <cfinput type="button" name="Submit" value="Submit" onclick="#prevalidateIt#" />
    </cfformgroup>
    <cfformgroup type="hbox" visible="yes" enabled="yes">
    <cfinput name="Reset" type="reset" id="Reset" value="Reset" />
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    </cfform>

     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2007 10:34 PM   in reply to saintsilver
    Why don't you delete the line submitForm(); and change from type="button" to type="submit"?

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2007 1:30 PM   in reply to saintsilver
    I don't think it's good, or even possible, to do alert(myField.text);. The assignment myField.text=x implied by SetVariable("myField.text", x) should be sufficient. It will put the value of x into the flash field.

    <html>
    <head>
    <title>Untitled</title>
    <script type="text/javascript">
    function setMyAlert()
    {
    x = "Yes1234";
    // Use SetVariable() to send a string value from JS to Flash
    window.document.myForm.SetVariable("myField.text", x);
    }
    </script>
    </head>

    <body>
    <cfsaveContent variable="getHashjs">
    <!--- Use getURL to call JS from Flash --->
    getURL("javascript:setMyAlert();");
    </cfsavecontent>

    <cfform action="#cgi.script_name#" method="post" name="myForm" id="myForm" format="Flash">
    <cfinput type="text" name="myField"><br>
    <cfinput type="button" name="btn" value="get it" onclick="#getHashjs#" >
    <cfinput type="submit" name="sbmt" value="send it">
    </cfform>
    </body>
    </html>
     
    |
    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