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 user clicks OK. CanI use jQuery here??
A:
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.
Ray Vernagus
2009-11-11 12:36:57
+1
A:
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
}
});
});
Chris
2009-11-11 12:40:20
+1 This code is more elegant.
Daniel Robinson
2009-11-11 12:41:53
it could be better... it was a very quick example just to illustrate the point. The if...return true isn't strictly needed.
Chris
2009-11-11 12:56:13
A:
Here's some very simple example code:
$("#submitButtonId").click(function(event) {
event.preventDefault();
if (confirm('Message containing values')) {
$("#formId").submit();
}
});
Daniel Robinson
2009-11-11 12:40:35