IE form submit bug

This had me baffled for 3 or 4 hours. What worked fine in firefox just didn’t work in IE, and appears to be a well known bug but I couldn’t find a work around to it at all.

It is probably best described in code:

<form>
….form stuff in here …..
<input type=”submit” name=”delete” value=”Delete this record” onclick=”return confirm(‘are you sure?’)”>
</form>

Now as I said it works as it should in firefox and pressing cancel stops the submission but in IE it continues to submit the form regardless.

Here is a fairly simple work around that uses a javascript variable which we set to n if the cancel button is pressed and then testing for it in the onsubmit event.

<script type=”text/javascript”>
var isok=’y';
</script>

<form onsubmit=”if(isok==’n’){isok=’y'; return false}”>
….form stuff in here …..
<input type=”submit” name=”delete” value=”Delete this record” onclick=”if(!confirm(‘are you sure?’)){isok=’n';}”>
</form>

This entry was posted in Code and tagged . Bookmark the permalink.

Leave a Reply