views:

265

answers:

3

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
+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
     }
    });
});

Events/bind - jQuery Docs

Chris
+1 This code is more elegant.
Daniel Robinson
it could be better... it was a very quick example just to illustrate the point. The if...return true isn't strictly needed.
Chris
A: 

Here's some very simple example code:

$("#submitButtonId").click(function(event) {

  event.preventDefault();

  if (confirm('Message containing values')) {

    $("#formId").submit();

  }

});
Daniel Robinson