2

Tried to call a javascript popup window using ColdFusion. Have not been able to do it.

The ColdFusion code is straight forward

<cfif notpaid>
    <script type="text/javascript">
    notpaid();
    </script>
</cfif>

It will pop up a window if a person is "notpaid". I tried it with alert() and it popup the alert box so the problem is not with this ColdFusion code.

One of the associated embedded javascripts is written as:

modalWin = new CreateModalPopUpObject();
modalWin.SetLoadingImagePath("/dev/images/loading.gif");
modalWin.SetCloseButtonImagePath("/dev/images/remove.gif");

function notpaid() {
    modalWin.Draggable=false;
    modalWin.ShowURL('https://www.sample.com/sample.htm', 320, 350, "Heading");
}
function HideModalWindow() {
    modalWin.HideModalPopUp();
    window.document.forms[1].submit();
}

The modalWin.ShowURL is the function that display the popup window and is proven working when it is associated with clicking, i.e. user click on a button and it will pop up the window.

In the new scenario, I am using ColdFusion to call without user interaction, but it won't pop up the window. I believe the problem lies with the javascript function notpaid(). I have tried different ways to no avail. I seen people talking about CF being server-side and javascript being client-side, but I do not know how to make the connection. I know with some proper code, it can be done. What am I missing here? Thanks in advance.

1
  • 2
    Likely possibilities A) Either the variable is false, so the CFIF block isn't hit. Add a <CFELSE> Message not displayed </CFIF> so you know if that's the problem B) A javascript error is occurring. Check your browser's debugging console for errors C) The code is being used somewhere that doesn't generate any output, like a CFC with output=false. Commented Dec 16, 2018 at 23:15

1 Answer 1

2

I have finally figured it out. By changing the "function notpaid()" to:

notpaid = function() {
    modalWin.Draggable=false;
    modalWin.ShowURL("https://www.sample.com/sample.htm", 320, 350, "Heading");
}   

and the pop up worked. Don't know why, but it did the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

Because in function notpaid()... you are creating a function named notpaid, but with cfif notpaid, you are looking for some sort of variable or cf object. When you create notpaid = function()... you're actually creating a variable named notpaid, so cffif sees that it exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.