Skip to main content
Participant
April 10, 2014
Question

Tryiing to call a CF function within a javascript function- CF10

  • April 10, 2014
  • 1 reply
  • 338 views

Hello! I am pretty new to CF, so please forgive me.

I am trying to call a CF fn within a javascript fn, and it doesnt seem to be working.

I am using coldfusion.ajax.submitform() within my javascript. within my ajax call, I am calling a cfc page which contains cfmail code.

I am wanting an onlick action (2 actions) to submit a form (this part works) and also send an email (this isnt working).

Here is my javascript function where I have included the ajax call (under 'my ajax code'):

-------------------------------------------------------------------------------------------------------------------

<cfoutput>

<script type="text/javascript">

    //**********************************************************************

    //  Function name: ValidateForm

    //    Description: Returns true if form is valid false otherwise.

    //**********************************************************************

    function ValidateForm()

    {

        if (!isRequired($('effect_job'), "Restriction Effect")) return false;

        if (!isRequired($('accommodation_description'), "Accommodation")) return false;

        if (!isRequired($('accommodation_manager_comment'), "Comment")) return false;

        if (!isRequired($('accommodation_action_date'), "Action Date")) return false;

        if (!isDate($('accommodation_action_date'), "Action Date")) return false;

        if (!isRequired($('accommodation_estimated_cost'), "Estimated Cost")) return false;

        if (!isNumber($('accommodation_estimated_cost'), "Estimted Cost")) return false;

        // Valid form

        return true;

    }

    //**********************************************************************

    //  Function name: SubmitUpdate

    //    Description: Validates and Submits form based on state argument

    //     Paramaters: New state

    //**********************************************************************

    function SubmitUpdate(state)

    {

        var inputs = $('effect_job', 'accommodation_description', 'accommodation_manager_comment',

            'accommodation_action_date', 'accommodation_estimated_cost');

        if (ValidateForm()) {

            // Enable any potentially disabled inputs

            for (var i=0; i<inputs.length; i++) { inputs.disabled = false; }

            // Submit

            Submit(state);

                                <!---MY AJAX CODE--->

                      ColdFusion.Ajax.submitForm ('document.medical_restriction_detail_form', '../include/CWBdelete.cfc?method=CWBDelete');

        }

    }

    //**********************************************************************

    //  Function name: Submit

    //    Description: Submits form based on state argument

    //     Paramaters: New Medical Restriction state

    //**********************************************************************

    function Submit(state)

    {

        // Set the new state

        $('medical_restriction_state').value = state;

        // Submit update

        $('page_action').value = 'update';

        document.#form_name#.submit();

    }

</script>

</head>

<body>

</cfoutput>

----------------------------------------------------------------------------------------------------------------------------------------------------

HERE IS MY CFC PAGE:

<cfcomponent extends="cfdocs.hris.med.Globals">

<!--- CWBDelete =================================================================

    Args:

        to       : Employee userid that will recieve mail.

        cc       : "test@email.com"

        bcc      : Employee id that will recieve mail.

        from    "test@email.com"

        subject  : Subject line of mail message.

=========================================================================== ---> 

<cffunction name="CWBDelete">

  <cfmail

    to = "test@email.com"

    cc = "test@email.com"

    bcc = "test@email.com"

    from ="test@email.com"

    subject = "testing">

    <CFMAILPARAM NAME="cwb_action_owner" VALUE="123454">

    <CFMAILPARAM NAME="cwb_app_id" VALUE="23">

    <CFMAILPARAM NAME="cwb_app_action_id" VALUE="54321">

    <CFMAILPARAM NAME="cwb_delete" VALUE="true">

</cfmail>

</cffunction>

---------------------------------------------------------------------------------------------------------------

Any ideas?

    This topic has been closed for replies.

    1 reply

    Carl Von Stetten
    Legend
    April 10, 2014

    At a minimum, you need to add access="remote" to the <cffunction> tag to allow it to be called remotely.

    -Carl V.