Solved

Getting JavaScript to run in a CFIF statement

Posted on 2004-08-06
14
971 Views
Last Modified: 2008-02-20
Hi.  I'm building this CF application and I have a JavaScript question.  In the following code, the CFIF statement is checking the CFQUERY which references a field in a database.  The field, in this case, is ADMIN and it is checking to see whether or not a person is an admin or not.  Y= Yes and N= No (Real cryptic huh?).  Anyway, the JavaScript should give a pop-up that says, "You do not have access to the Admin feature of this application" and redirect them back to the referring page.  How do you do that?  I've played with it a bunch of ways but can't get the JavaScript to run.  This is what I have so far:

<CFIF userroles.ADMIN EQ "N">
<SCRIPT LANGUAGE="JavaScript1.2">
function r(){
alert("You do not have access to the Admin feature of this application.");
document.location("RefferingPage.cfm");
return false;}
</SCRIPT>      
</CF>

<!--- The Code Below is in my Application.cfm page and contains the query --->
<CFQUERY NAME="userroles" DATASOURCE="#request.datasource#" username="#request.username#" password="#request.password#">
Select
   ADMIN
From
   #request.prefix#.t_tablename
Where
   upper(NTID)='#ucase(request.user_id)#'
</CFQUERY>  
0
Comment
Question by:FSUKXAZ
  • 6
  • 5
14 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 11738403
Like this:
<CFIF userroles.ADMIN EQ "N">
<SCRIPT LANGUAGE="JavaScript1.2">
alert("You do not have access to the Admin feature of this application.");
window.location="RefferingPage.cfm";
</SCRIPT>    
</CFIF>

0
 
LVL 1

Author Comment

by:FSUKXAZ
ID: 11820126
It's sort of working.  You now get the alert error message appearing, but when you close it it still takes you to the admin page. So what to do now???
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11821176
So you say after the alert is closed you do not go automaticaly to: RefferingPage.cfm
0
 
LVL 1

Author Comment

by:FSUKXAZ
ID: 11821686
Right. You go on to the Admin page as you would if you WERE an admin, as opposed to going back to the referring page.  I've tried it a few different ways and can't get it to work.  However, the alert message is working.  You just get sent to the same page anyway.  Does the URL have to be absoulte?  I'm using a relative URL that is in the exact same folder as the admin page.  I have to program for Dev, QA, and Production so links are better off being relative.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11822245
Now I do not understand!?!
If this snippet redirects you to RefferingPage.cfm, so what is your problem?
<CFIF userroles.ADMIN EQ "N">
<SCRIPT LANGUAGE="JavaScript1.2">
alert("You do not have access to the Admin feature of this application.");
window.location="RefferingPage.cfm";
</SCRIPT>    
</CFIF>

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

 
LVL 1

Author Comment

by:FSUKXAZ
ID: 11823275
Sorry to confuse you. Here is the process:  A person is on the SecurityTeam.cfm page and clicks on the button to take you to the SecurityTeamAdmin.cfm page.  Here is the ACTUAL code on the SecurityTeamAdmin.cfm  page.

<CFIF userroles.ADMIN EQ "N">
<SCRIPT LANGUAGE="JavaScript1.2">
   alert("You do not have access to the Admin feature of this application.");
   window.location("SecurityTeam.cfm");
</SCRIPT>
</CFIF>

You see... It is supposed to put them back (or keep them) on the SecurityTeam.cfm page and not let them get to the SecurityTeamAdmin.cfm page.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11823620
Pleas keep two things separate: the ColdFusion side and the browser side.
So now, the upper code snippet is executed on ColdFusion side. What do you see as generated html page in browser?
0
 
LVL 1

Author Comment

by:FSUKXAZ
ID: 11823643
You've lost me now.  My last post explains it perfectly.  Their are no HTML pages on this application.  They are all .CFM
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11823863
But the browser understand only HTML :-)
I ask you only to look into browser html source what code apears there. This is the only relevant result. It can also be a browser caching problem...

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11824892
So what HTML code do you see on the SecurityTeamAdmin.cfm page when you look into browser's page source?
Do you see the script which should redirect the user back?

0
 
LVL 1

Author Comment

by:FSUKXAZ
ID: 12068010
Sorry, I haven't been back here in a while.  I want to give all the points to Zvonko.  However, the page still doesn't work properly.  

To answer your question, no, I do not see the script to redirect the user back when I view source.  However, I'm an Admin, so I should be getting to the SecurityTeamAdmin.cfm page.  A non-admin gets the same code but with this code also at the top:
 

<SCRIPT LANGUAGE="JavaScript1.2">
   alert("You do not have access to the Admin feature of this application.");
   window.location("SecurityTeam.cfm");
</SCRIPT>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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