Getting JavaScript to run in a CFIF statement

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>  
LVL 1
Todd VernonSenior Coldfusion DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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
ZvonkoSystems architectCommented:
So you say after the alert is closed you do not go automaticaly to: RefferingPage.cfm
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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
ZvonkoSystems architectCommented:
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
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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
ZvonkoSystems architectCommented:
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
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
You've lost me now.  My last post explains it perfectly.  Their are no HTML pages on this application.  They are all .CFM
0
ZvonkoSystems architectCommented:
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
ZvonkoSystems architectCommented:
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
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.