Link to home
Start Free TrialLog in
Avatar of viola123
viola123

asked on

How to display "Confirmation box" in JSP?

hi all,
i try to display a confirmation box when clicking a button in JSP. but it does not seem to work.
pls help me solve this issue.
<%@ include file="/common/includes.jsp"%>
<script type="text/javascript">
<!--
function isProcess()
{
  var answer = confirm ("Are you sure you want to continue?");
  if (answer)
      return true;
    else
      return false;
}
// -->
</script> 
<% 
if (form.ButtonClicked("ok_button"))
  {
    if (form.ValidateFormFields())
    {
        boolean answer= true;
      if(busLogic.IsIdenticalTrans())
      {
        //get confirmation result
        answer=  isProcess();
         //when compile, it complains like "isProcess() is undefined type". what's going on? how to do it in a correct way? pls help!!!
      }
      if(answer)
      {
         //if confirmation is Yes,continue to do something 
       }
    }
  }
%>

Open in new window

Avatar of rrz
rrz
Flag of United States of America image

I think you are mixing Javascript(happens in the browser at client) with JSP(at the server).    
If you want to know what the client answers, then you will have to submit a form ( or use AJAX) to the server.
Please tell us what you are trying to accomplish.  Maybe an expert will suggest a way to get done.
You are allowed, in JSP to have "HTML" code.  The "HTML" code that you include can contain stuff like:

<script type='text/javascript>
</script>

And the JavaScript can include a call to confirm()



var ans = null
 
if ( ans = confirm( 'Are you sure?' ) ) {
  alert( 'ok' )
} else {
  alert( 'cancel' )
}

Open in new window

Avatar of viola123
viola123

ASKER

hi ,
i try to put this javascript into a jsp file and reference it in my html page. but it still complains like "the method isProcess(String) is undefined for the type". i dont know how to solve it.

//in popup.jsp file:
//confirmation box
function isProcess(msg)
{
  var answer = confirm (msg);
  if (answer)
      return true;
    else
      return false;
}
********************************************
//in my main form contentHeader.jsp:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- STYLESHEETS -->
    <link rel="stylesheet" href="/private/common/private_content.css" type="text/css" media="all" />
    <link rel="stylesheet" href="/private/common/private_print.css" type="text/css" media="print" />
    <!-- end stylesheets -->
 
    <!-- INCLUDED JAVASCRIPTS -->
    
    <script type="text/javascript" src="/private/common/popup.js"></script>
        <!-- end scripts -->
      </head>
  <body >
    <table width="100%" cellpadding="0" cellspacing="0" class="wrapper" valign="top">
	  <tr>
	  	<td colspan="2">
          <%@ include file="/common/header.jsp" %>
        </td>
      </tr>
	  <tr valign="top">
	    <td width="185">
          <%@ include file="/common/menu.jsp" %>
		</td>
	    <td align="left" style="padding-left:10px; padding-right: 10px; padding-bottom: 20px; width: 100%;">
*****************************************************
//in my content form myform.jsp:
<%@ include file="/common/includes.jsp"%>
<% 
if (form.ButtonClicked("ok_button"))
  {
    if (form.ValidateFormFields())
    {
        boolean answer= true;
      if(busLogic.IsIdenticalTrans())
      {
        //get confirmation result
        answer=  isProcess("Want to continue?");
         //when compile, it complains like "the method isProcess(String) is undefined for the type". what's going on? how to do it in a correct way? pls help!!!
      }
      if(answer)
      {
         //if confirmation is Yes,continue to do something 
       }
    }
  }
%>
 
<c:import url="/common/contentHeader.jsp" />
<form>
  //this is the form
</form>

Open in new window

hi all,
all i try to do is to popup a confirmation box on client side and get the answer on server side, so i can use the answer to decide if we need to go to next step or not. i know how to do it in c#/asp.net, but i am new to jsp/java. so need your help!!!!

thanks
viola
>all i try to do is to popup a confirmation box on client side and get the answer on server side,  
The confirm  is a javascript method.  When the user makes a decision, you can submit a form programmatically to the server. The server can do the next step and send a response to the client.
>i know how to do it in c#/asp.net  
JSP should be the similar.
rrz@871311:
could you pls give me an example?
when user click the submit button, the confirmation box pops up. if user choose YES, go to next step, If choose NO, then stay at current form.
thanks a lot
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks heaps