Solved

Getting JavaScript to run in a CFIF statement

Posted on 2004-08-06
14
982 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
Debugging Html 8 31
Prevent / reduce email harvesting using an image – javascript approach ? 14 68
Html date format 9 20
Aspx calendar pop up control 3 25
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

713 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