Solved

javascript Confirmation msg box with coldfusion

Posted on 2010-11-24
16
518 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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