Reputation: 41
adding confirm box
Here is my code and I want to add a confirmation box to it.
I have a form with two submit
buttons. I need the confirmation box with them and then send to the next page. How can I do this?
this is the code for confirmation box,how can i place it in my form ?
onclick="return confirm('Are you sure?');"
myform.jsp
<form id="form1" name="form1" method="post" action="">
<p> </p>
<p align="center">Enter your choice:-
<label> <br />
<label>
<input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';this.form.submit();" />
</label>
<br />
</br>
<label>
<input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';this.form.submit();" />
</label>
<br/>
</div>
</form>
Upvotes: 2
Views: 10180
Reputation: 3428
On button class try this
$('.class').appendTo('body')
.html('<div><h6>Yes or No?</h6></div>')
.dialog({
modal: true, title: 'message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
doFunctionForYes();
$(this).dialog("close");
},
No: function () {
doFunctionForNo();
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).remove();
}
});
Upvotes: 2
Reputation:
See this code confirm box works in this way and one sugesstion your code need a lot pf improvement
<html>
<head>
<script>
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
{
alert("You pressed OK!")
}
else
{
alert("You pressed Cancel!")
}
}
</script>
</head>
<body>
<input type="button" onclick="disp_confirm()" value="Display a confirm box">
</body>
</html>
Upvotes: 0
Reputation: 2121
The following snippet is the solution. You need to remove this.form.submit()
as the buttons are submit buttons and by default they submit.
Just add onsubmit=" return window.confirm('Are you sure?');"
to the form and remove this.form.submit()
from submit buttons.
<form id="form1" name="form1" method="post" action="" onsubmit=" return window.confirm('Are you sure?');">
<p> </p>
<p align="center">Enter your choice:-
<label> <br />
<label>
<input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';" />
</label>
<br />
</br>
<label>
<input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';" />
</label>
<br/>
</div></form>
Upvotes: 0
Reputation: 3005
<input type="submit" name="Submit" value="Delete" onclick='confirm(this,"delete1.jsp?flag=1&act=1")' />
<input type="submit" name="Submit" value="delete" onclick='confirm(this,"logi.jsp?flag=1&act=1")' />
function confirm(this,foo1)
{
var foo = confirm('Are you sure?');
if (foo) {this.form.action=foo1;this.form.submit();}
else {alert('Try Later');}
}
Upvotes: 0
Reputation: 7887
try this
<form id="form1" name="form1" method="post" action="/your/url.xyz" onsubmit="return confirm('bla bla');">
Upvotes: 0