PROBLEMS USING JAVASCRIPT DIALOG IN JSP

Discussions

Web tier: servlets, JSP, Web frameworks: PROBLEMS USING JAVASCRIPT DIALOG IN JSP

  1. PROBLEMS USING JAVASCRIPT DIALOG IN JSP (2 messages)

    I HAVE A DIALOG BOX WHICH REQUIRES THE USER TO CONFIRM THEIR REQUEST, IE TO DELETE A RECORD FROM A DATABASE. I'M UNABLE TO SWITCH ON THE USER'S CHOICE. THE SCRIPLETS ALWAYS EXECUTES IRRESPECTIVE OF THE SCRIPTS RETURN VALUE. CAN ANYONE TELL ME WHAT I NEED DO OR PROFFER ALTERNATIVE SOLUTION.

    // -- EXAMPLEC CODE

    <SCRIPT>
    function confirmDelete(){
          return confirm("Do you want to delete or Cancel");
    }
    </Script>

    if(deleteX != null ){ %>
           <script language ="javascript">
             if(confirmDelete()){
               <% xxx.deleteX();
                  xxxx = null; %>
             }
          </script>
    } %>
  2. You logic is wrong. The JSP is compiled in to HTML on the server before serving it up to your browser. In your code you want to perform an action xxx.deleteX() on server side, pending on the condition that the client will click yes or no in your confirm box. However, by the time the client see the confirm box, the JSP has already been compiled.

    Maybe the deleteX() action need to be part of another page where the user will submit the info to this new page. So your flow is this:

    page 1 ---> confirm (yes / no) ---> submit to new page ---> check request.getParameter() ---> perform xxx.deleteX() if neccessary.
  3. This is happnening bcoz u have implemented ur delete method wrongly. you are checking the condition in javascript. so it wont apply to jsp. it will always execute the delete irrelevent of ur confirm check. Try following code.

    <SCRIPT>
    function confirmDelete(){
          x= confirm("Do you want to delete or Cancel");
          if(x){
          //submit ur form to the same page and set the value
            of hidden variable to delete and then get the value
           of x on top of ur jsp code and if its match ur set
           value then call the delete method.
          }

    }
    </Script>

    hope this will help
    Akil