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
    Regular Coder
    Join Date
    Mar 2004
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple confirm code not working

    This is probably just a stupid mistake that I'm missing, but I'm using this code to confirm a choice to delete a post:

    Code:
    function prepsub {
    var ask = window.confirm("Are you sure you want to delete the selected post?");
    if (ask) {
    document.forms.form.submit();
    }
    }
    The HTML code I use is this:

    Code:
    <button onclick="javascript:prepsub();">Delete Selected Post</button>
    I think I heard that the <button> tag is deprecated, and that might be the reason, but I don't think it is because I've successfully used it for other similar purposes before.

    For some reason on Mozilla it doesn't show the confirm dialog box ask must return true because it goes ahead and submits it. On IE it doesn't show the confirm box and refuses to submit at all. Am I making a stupid mistake here?

    Thanks,
    Matt

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Right off i can see you are missing your parenthesis:

    function prepsub()

    There might be something else but try that first.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			function prepsub() {
    				return window.confirm("Are you sure you want to delete the selected post?\n\nReally?\n\nDo you have thought about it long enough?\n\nI mean.. you can't get your post..\n\nSo.. are you really really sure?\n\nDon't want to think about it twice?\n\nAm I annoying you? ^^");
    			}
    		</script>
    	</head>
    	<body>
    		<form onSubmit="return prepsub()">
    			<input type="submit" name="delete" value="delete selected post">
    		</form>
    	</body>
    </html>
    This works.

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the code even if the confirm will take a little editing lol.

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <button onclick="javascriptrepsub();">Delete Selected Post</button>


    <input type="button">


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "


  •  

    Posting Permissions

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