Hi, i want to set a coldfusion variable to undefined within a javascript function, i just written as below, but without calling the method it automatically set the variables on page load. Can anybody help me in the same i want to set the below variable only on call of resetForm(). Please reply me asap. Thanks

function resetForm()
    {

        <cfoutput>
            <cfset form.rdoSensitivity = JavaCast( "null", 0 )/>
            <cfset form.rdoMgtLevel = JavaCast( "null", 0 )/>
        </cfoutput>

        document.getElementById("addButton").disabled = false;
        document.getElementById("removeButton").disabled = false;

    }

You've got things reversed. By the time the Javascript function executes, ColdFusion has done its work and receded into the background. There's nothing to set.

The solution is pretty easy. You have to understand the client side and server side code execution time. As mentioned above by Wayne 3, by the time javascript function is called, ColdFusion is already been executed. To be more specific, First ColdFusion code is executed to get HTML and javascript output, and then when the response reaches to browser, we get a chance to execute javascript code.This is all about client and server side. Now the solution for you.

Use AJAX call from your javascript method to communicate with your server and do whatever ColdFusion operation you want to do. That is the easiest way you can pick. Please use $.ajax to acomplish your task.

Please let me know if this helps you.

Regards,
Dipak

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.