Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Action on the response from an alert with yes/no

    I was wondering if someone can give me a quick example of how to make an alert on click - where if the user toggles yes then submit, and if the user toggles no, then do nothing.

    I have come up with this so far:

    Code:
    <SCRIPT type="text/javascript">
    	function validateForm() {
    		alert ("Confirmation: End session?");
    		return false;
    		}
    </SCRIPT>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Use a confirm box.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Where abouts in the manual can I find this?

  • #4
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Code:
    <SCRIPT type="text/javascript">
    	function confirmForm() {
    		confirmation = confirm("Confirmation: End session?");
    		if (confirmation == false) {
    			return false;
    		}
    	}
    </SCRIPT>
    Solved.

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,411
    Thanks
    13
    Thanked 357 Times in 353 Posts
    there is no need to test for false to return false ... simply return confirm()’s return value.
    PHP Code:
    function confirmForm() {
        return 
    confirm("Confirmation: End session?");

    your original function has the problem that (if the confirmation is true) the function returns a falsy value (namely undefined) and not a truthy value, which can fire back when you do onsubmit="return confirmForm()" or
    PHP Code:
    if (!confirmForm()) {
        
    // do not submit

    Last edited by Dormilich; 07-05-2012 at 09:34 AM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •