How can I add a cancel button to an alert window?
I have used the confirm() method but when the submit button is clicked the confirm window pops up, but when clicking on cancel button, the form's data is stored.
I just want clicking on the cancel button to not store the data and leave the previous form as it is. This is my code:
function submitdata()
{
var r=confirm("Are You Sure You Want To Proceed?");
if(r==true)
{
alert("Record is saved");
}
else
{
alert("Cancelling Transaction");
javascript:history.go(0);
}
}
<form action="" name="test" onsubmit="return submitdata();">
<input type="text" />
<input type="submit" />
</form>
<script type="text/javascript">
function submitdata() {
var r=confirm("Are You Sure You Want To Proceed?");
if(r==true) {
alert("Record is saved");
} else {
alert("Cancelling Transaction");
javascript:history.go(0);
}
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With