What I'm trying to do is make a confirm dialog box popup when I press to create an item in my view. From what I understand from reading other posts (correct me if I'm wrong) is by using jquery. I'm not very familiar with jquery/javascript so I'm doing my best to understand what I'm doing. The code i found online is this.
<form method="post">
<input id="Create" name="Common" type="submit" value="Create" />
<script type="text/javascript">
$(document).ready(function () {
$("#Create").click(function (e) {
// use whatever confirm box you want here
if (!window.confirm("Are you sure?")) {
e.preventDefault();
}
});
});
How it is right now every time I press the button it fires my POST create method in my controller right away without showing a dialog box. Can someone explain me why that happens and how i can fix it. I have tried adding code where //use whatever confirm box you want here
is written but I don't really know what I'm looking for or what it needs to be written there.
Posts i have read
Where i got the above code from