Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

call javascript function from cfm

Posted on 2006-10-26
Last Modified: 2013-12-24

I am sure this can be and has been done many times, but I just could not get it right. I want to call a javascript function, which could be as simple as this:
<script type="text/javascript">
function disp_alert()
alert("You have not login for at least 6 months.")

My calling part is in this context, but I am sure I did not get the syntax right.
<cfif ---test condition is true--- >

Could any body tell me how this can be done? And if I don't have to use javascript, what is the cf equivalent of accomplishing the task?

Question by:ommer
  • 3
  • 2
LVL 13

Accepted Solution

srikanthmadishetti earned 30 total points
ID: 17814819
hey ommer

see when you are using cflocation alert will not pop up

so better do this

<cfif ---test condition is true--- >
  <script type="text/javascript">

alert("You have not login for at least 6 months.")
window.location="login.cfm" ;

Author Comment

ID: 17814930
Ok, that may solve this one, but is there a higher level location where I can put my j function that I could call it from other places on the same cf page?

Also, if this is the case, I should be able to get rid of javascript all together, and use some cf native way to warn users. I am pretty new in cf. Could you show me how to do that?

LVL 13

Expert Comment

ID: 17814967
with cf u cannot warn the users and more over if you are using cflocation it will redirect the page and you cannot see any warn messages like JS alert or even a div .

see dis url


it was the same issue look at the last comments
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.


Author Comment

ID: 17815117
Cool! One more question.

I tried to use your way like this, but seems did not pass my user_id over.

alert("You have not login for at least 6 months.")
LVL 13

Expert Comment

ID: 17815496
you cannot pass like that in js

window.location="MaintainAcct.cfm?user_id=login" + login.user_id ;
LVL 39

Assisted Solution

gdemaria earned 20 total points
ID: 17817070

 ommer, the coldfusion way of doing this is simply to direct the user to a new page that tells them the message.

 <cfif ( has it been a long time? )>  <!---- put your test in here ----->

     <cflocation url="Its_been_a_long_time.cfm">  <!--- go to a page to tell them whatever you want --->


 Alternatively, you just set a message that you display on the page.  Most web programmers designate a spot on their pages for error messages (or info messages).   If you are doing this, set the message to appear on the page when the enter.

 Say this is the homePage.cfm...

 <cfif ( has it been a long time? )>  

       Hey its been a long time!   <!---- tell them on the page you are drawing --->


 It seems you know javascript better than coldfusion, try not to think in javascript though.  js works on the client while codlfusion processes long before the web page is drawn...

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question