Show message box with form entries on submitting the from in asp.net mvc
I have a form which takes multiple inputs from user. Now I wanna show the inputs in a confirmation dialog and submit the form if u开发者_C百科ser clicks OK. CanI use jQuery here??
Yes you can. The way I would do it would be to bind to the form's submit event, and display a standard JavaScript confirmation box:
Non-specific example:
$(function(){
$('#myform').bind('submit', function(e){
if(confirm('Write your confirmation message here')){
return true; //submit form
}else{
return false; //suppress submission
}
});
});
Events/bind - jQuery Docs
you can do it on the button onclick event.
<p>
<input type="submit" value="Approval of payment"
onclick="if (confirm('Are you sure?')) {return true;} else {return false;}" />
</p>
that work for me =)
Of course you can use jQuery here. =)
Dino Esposito wrote an excellent article on using jQuery UI in the context of ASP.NET MVC. One of things that he walks through is a dialog-based form.
Here's some very simple example code:
$("#submitButtonId").click(function(event) {
event.preventDefault();
if (confirm('Message containing values')) {
$("#formId").submit();
}
});
I wrote a blog post here that goes through how to do this using AJAX including making client side validation work. I wrapped it all up in a custom HTML extension method to make it reusable. Check it out.
精彩评论