HTML - How to do a Confirmation popup to a Submit button and then send the request?

后端 未结 5 1864
北海茫月
北海茫月 2020-12-04 19:22

I am learning web development using Django and have some problems in where to put the code taking chage of whether to submit the request in the HTML code<

相关标签:
5条回答
  • 2020-12-04 19:30

    Another option that you can use is:

    onclick="if(confirm('Do you have sure ?')){}else{return false;};"

    using this function on submit button you will get what you expect.

    0 讨论(0)
  • 2020-12-04 19:33

    The most compact version:

    <input type="submit" onclick="return confirm('Are you sure?')" />
    

    The key thing to note is the return

    -

    Because there are many ways to skin a cat, here is another alternate method:

    HTML:

    <input type="submit" onclick="clicked(event)" />
    

    Javascript:

    <script>
    function clicked(e)
    {
        if(!confirm('Are you sure?')) {
            e.preventDefault();
        }
    }
    </script>
    
    0 讨论(0)
  • 2020-12-04 19:37

    Use window.confirm() instead of window.alert().

    HTML:

    <input type="submit" onclick="return clicked();" value="Button" />
    

    JavaScript:

    function clicked() {
        return confirm('clicked');
    }
    
    0 讨论(0)
  • 2020-12-04 19:44
    <script type='text/javascript'>
    
    function foo() {
    
    
    var user_choice = window.confirm('Would you like to continue?');
    
    
    if(user_choice==true) {
    
    
    window.location='your url';  // you can also use element.submit() if your input type='submit' 
    
    
    } else {
    
    
    return false;
    
    
    }
    }
    
    </script>
    
    <input type="button" onClick="foo()" value="save">
    
    0 讨论(0)
  • 2020-12-04 19:47

    I believe you want to use confirm()

    <script type="text/javascript">
        function clicked() {
           if (confirm('Do you want to submit?')) {
               yourformelement.submit();
           } else {
               return false;
           }
        }
    
    </script>
    
    0 讨论(0)
提交回复
热议问题