javascript Confirmation msg box with coldfusion

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.
s_hausenAsked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
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
 
s_hausenAuthor Commented:
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
 
_agx_Commented:
The above code should work fine, once you substitute the paths of you pages.  But it's not very elegant ..
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
s_hausenAuthor Commented:
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
 
_agx_Commented:
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
 
s_hausenAuthor Commented:
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
 
_agx_Commented:
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
 
s_hausenAuthor Commented:
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
 
_agx_Commented:
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
 
_agx_Commented:
... and Happy Thanksgiving to you too!
0
 
s_hausenAuthor Commented:
ok, i look at it again :) thanks again for your help and being patient with me..
0
 
_agx_Commented:
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
 
s_hausenAuthor Commented:
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
 
s_hausenAuthor Commented:
<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
 
_agx_Commented:
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
 
s_hausenAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.