...

View Full Version : Simple confirm code not working



MattJakel
07-02-2004, 05:26 AM
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:



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:



<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

JohnKrutsch
07-02-2004, 05:40 AM
Right off i can see you are missing your parenthesis:

function prepsub()

There might be something else but try that first.

dumpfi
07-02-2004, 08:18 AM
<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. :D

MattJakel
07-02-2004, 03:41 PM
Thanks for the code even if the confirm will take a little editing lol. ;)

jamescover
07-02-2004, 05:05 PM
<button onclick="javascript:prepsub();">Delete Selected Post</button>


<input type="button">


-james



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum