Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript Confirmation msg box with coldfusion

Posted on 2010-11-24
16
Medium Priority
?
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 1000 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 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