Solved

javascript Confirmation msg box with coldfusion

Posted on 2010-11-24
16
514 Views
Last Modified: 2012-05-10
I am using coldfusion. I have an insert statement and after that statement, I want to let user to click "YES" to go to next page and "NO" to go back to previous page using JavaScript Confirmation msg box.

<CFQUERY name="Insert" datasource="MyDataSource">
INSERT into BUDGETITEM
(
CATEGORY,SBUID,COSTCENTER,ACCTCODE,COSTCENTERID,ACCTCODEID
)
VALUES
('#FORM.CATEGORY#',#FORM.SBUID#,'#FORM.COSTCENTER#','#FORM.ACCTCODEID#','#FORM.COSTCENTER#','#FORM.ACCTCODEID#'
)
</CFQUERY>

Open in new window


javascript Confirmation msg box to redirect the user to diffrent pages according to YES or NO button.. any help and comment would be deeply appreciated.
0
Comment
Question by:s_hausen
  • 8
  • 8
16 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 34210565
Basic confirmations are simple (though a little ugly).  But personally, I don't like having javascript prompts on the same page as inserts. I'm always afraid they're going to run twice ..

http://www.w3schools.com/js/js_popup.asp
<script type="text/javascript">
     var wasConfirmed = confirm("Go to next page?");
      if (wasConfirmed) {
          document.location.href="http://yoursite/nextPage.cfm";
      }
      else {
            document.location.href="http://yoursite/previousPage.cfm";
           // .... or history.go(-1);
      }
</script>

0
 

Author Comment

by:s_hausen
ID: 34210589
Hi agx,
I want to use javascript Confirmation msg box after insert statement on same page,  and redirect the user to previous or next pages according the user selection.. is there a way i can use it???
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34210623
The above code should work fine, once you substitute the paths of you pages.  But it's not very elegant ..
0
 

Author Comment

by:s_hausen
ID: 34210632
so you are saying if i use the confirm message javascript after insert statement it'll run the javascript without firing the event??

<CFQUERY name="Insert" datasource="MyDataSource">
INSERT into BUDGETITEM
(
CATEGORY,SBUID,COSTCENTER,ACCTCODE,COSTCENTERID,ACCTCODEID
)
VALUES
('#FORM.CATEGORY#',#FORM.SBUID#,'#FORM.COSTCENTER#','#FORM.ACCTCODEID#','#FORM.COSTCENTER#','#FORM.ACCTCODEID#'
)
</CFQUERY>
<script type="text/javascript">
     var wasConfirmed = confirm("Go to next page?");
      if (wasConfirmed) {
          document.location.href="http://yoursite/nextPage.cfm";
      }
      else {
            document.location.href="http://yoursite/previousPage.cfm";
           // .... or history.go(-1);
      }
</script>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34210637
I'm saying the javascript code will do exactly what you asked

...after that statement, II want to let user to click "YES" to go to next page and "NO" to go back to previous page using JavaScript Confirmation msg box.

... but it's not a very friendly way of doing things :)
0
 

Author Comment

by:s_hausen
ID: 34210668
Hi agx,
I believe there's some kind of misunderstanding & I do accept its my fault not to explain my question in detail. I do know how to write the javascript confirm msg code. but i wanted to know how i can use it after insert statement in my page. so user can go to next or previous page
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34210679
I must be missing something :) .. because it should do exactly what you describe.  Since it's javascript code (client side), it always runs after any CF code.  So what'll happen is

1) CF runs the INSERT query on the server
2) CF returns the page html to the browser
3) User get's prompted to "Go to next page"
   - If they say "yes", javascript sends them to nextPage.cfm
   - Otherwise, javascript sends them to previousPage.cfm





0
 

Author Comment

by:s_hausen
ID: 34210695
i am already using many other tags after insert statement including cftry & cfcatch, cfscript, cftransaction and cfif statements. but whenever i try to use javascript with all other tags it doesn't run. I thought there must be some otherway to use confirmation. anyway hopefully i'll find something. thanks for your help and do appreciate it. happy thanksgiving :)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:_agx_
ID: 34210706
No, it should work just fine.  Are you sure the javascript code is even being generated?  If you've got a bunch of cfif's maybe you accidentally skipped it. Do a "view source".  Do you see the javascript code in the html?  
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34210709
... and Happy Thanksgiving to you too!
0
 

Author Comment

by:s_hausen
ID: 34210713
ok, i look at it again :) thanks again for your help and being patient with me..
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34215848
You're welcome.  I just wanted to confirm your approach is right. So if it's not working, something in the code is going wrong.  Most likely the javascript isn't being generated at all.  Might also be special characters preventing the javascript from displaying correctly.  But a quick check of view source should tell you which one is the culprit.
0
 

Author Comment

by:s_hausen
ID: 34223371
Hi agx,
sorry for late response. I got the solution & its as under:

<script>
var answer = confirm("Are you sure?");
if (!answer) {window.location="events.cfm";}
if (answer) {window.location="events1.cfm";}
</script>

Open in new window


if we use else then it won't work..anyway, again I apologize for late response and thanks again for all your help.
0
 

Author Comment

by:s_hausen
ID: 34223432
<cfform action="cfc/FirstCFC.cfc?method=ListFilms">
<input name="SearchString" >
<input type="Submit" value="Search">
</cfform>

<cfcomponent>
	<cffunction name="ListFilms" access="remote" returnType="query" output="false">
	  <cfargument name="SearchString" required="no" default="">
	  <cfset var GetFilms = "" >
	  <!--- ListFilms body --->
	  <cfquery name="GetFilms" datasource="OWS">
SELECT FilmID, MovieTitle
FROM Films

<cfif Arguments.SearchString NEQ "">
WHERE MovieTitle LIKE <cfqueryparam value="%#Arguments.SearchString#%" cfsqltype="cf_sql_clob" maxlength="255"> 
</cfif>
        </cfquery>
	  <cfreturn GetFilms>
	</cffunction>
</cfcomponent>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34223976
Hm.. weird.  As long as the braces {} are placed correctly it should work fine.  It works fine for me. Not sure what the problem was. Anyway, glad it's working now. :)
0
 

Author Comment

by:s_hausen
ID: 34231359
i guess i am using cfoutputs with coldfusin form variables with sql server functions...anyway, thanks again for your help. I do appreciate it...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

13 Experts available now in Live!

Get 1:1 Help Now