简体   繁体   中英

I want to display a confirmation dialog before displaying output

I want to display a confirmation dialog box like "Do you want to continue?" If "yes", I want to popup a message displaying form output, if "No" I want to stay on the same page.

In the code shown below I am navigating to facto.html for displying the output, but I want to show a popup with its contents instead. How can I do that?

My index.html :

<!DOCTYPE html>
<html>
  <head>
    <title>Lift From Scratch</title>
      <script type="text/javascript">
         <!--
            function getConfirmation(){
               var retVal = confirm("Do you want to continue ?");
               if( retVal == true ){
                  <!--document.write("continue")-->
                  <!--window.location.href = '/facto.html';-->
                  return true;
               }
               else{
                  alert("Don't continue")
                  <!--window.location.href = 'index.html';-->
                  return false;
               }
            }
         //-->
      </script>
  </head>
  <body>
    <h1>Finding Factorial</h1>
    <div id="main" class="lift:surround?with=default&at=content">
        <form method="post">
          <table>
              <tr><td> Enter a Number:</td> <td><input name="num" type="number"></td></tr>
              <tr><td><input type="submit" value="Submit" onclick="getConfirmation();" formaction="facto"></td>
                  <td><input type="reset" value="Reset"></td>
              </tr>
          </table>
        </form>
      </div>
    </div>
  </body>
</html>

facto.html:
<div data-lift="factorial">
    <p>Factorial is: <span name="paramname"></span></p>
</div>

Try something like this:

 function validateMyForm() { if( confirm('Are you sure?') ) return true; // will submit the form else return false; // do not submit the form } 
 <form name="myForm" onsubmit="return validateMyForm();"> <input type="submit" value="Submit" /> </form> 

You're going to probably want to fall back to JavaScript for this one, to be honest. You can make the form an AJAX form using Lift's SHtml.makeFormsAjax helper, then you can bind your submit button using SHtml.ajaxSubmit . The callback you pass to ajaxSubmit should return a JsCmd . That JsCmd can trigger the display of the popup. You can even render the popup's contents by using SHtml.idMemoize .

If you describe this question in a little more detail on the Lift group , you will probably find folks willing to help you with some of the more specific aspects of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM