Solved

call javascript function from cfm

Posted on 2006-10-26
6
551 Views
Last Modified: 2013-12-24
Hello,

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.")
}
</script>

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

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?

Thanks!
0
Comment
Question by:ommer
  • 3
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
srikanthmadishetti earned 30 total points
Comment Utility
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" ;
</script>
   
</cfif>
0
 

Author Comment

by:ommer
Comment Utility
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?

Thanks!
0
 
LVL 13

Expert Comment

by:srikanthmadishetti
Comment Utility
ommer
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

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_22007584.html

it was the same issue look at the last comments
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:ommer
Comment Utility
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.")
window.location="MaintainAcct.cfm?user_id=login.user_id"
0
 
LVL 13

Expert Comment

by:srikanthmadishetti
Comment Utility
you cannot pass like that in js

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

Assisted Solution

by:gdemaria
gdemaria earned 20 total points
Comment Utility

 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 --->

 </cfif>


 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? )>  

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

 </cfif>


 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...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now