Solved

javascript Confirmation msg box with coldfusion

Posted on 2010-11-24
16
513 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
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

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!

 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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_
Comment Utility
... and Happy Thanksgiving to you too!
0
 

Author Comment

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

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
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
Comment Utility
<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_
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now