Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
HTML
<% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "postAddSupplemental", onsubmit = "return submitSupplemtal(this)"}))


in the above line onsubmit i have called javascript function like as below

JavaScript
function submitSupplemtal(frm) {
        
        var tdata = $(frm).serialize();
        $.ajax({
            url: $.url('EventCommand/ProcessAddSupplemental'),
            type: 'POST',
            dataType: "json",
            cache: false,
            data: tdata,
            success: function (data) {
                if (data != null) {
                               
                    showResult(null, data, false);
                }
                else {
                    showResult(null, "Added successfully", false);
                }
            }
        });
       
    }


How to cancel submit a form using javascript function when json returns failure message
Posted
Updated 8-May-12 20:38pm
v2

1 solution

JavaScript
function submitSupplemtal(frm) {
        
        var tdata = $(frm).serialize();
        $.ajax({
            url: $.url('EventCommand/ProcessAddSupplemental'),
            type: 'POST',
            dataType: "json",
            cache: false,
            data: tdata,
            success: function (data) {
                if (data != null) {
                               
                    showResult(null, data, false);
                    return false;//Added By B Birajdar
                }
                else {
                    showResult(null, "Added successfully", false);
                    return true;//Added By B Birajdar
                }
            }
        });
       
    }
 
Share this answer
 
Comments
Rupa1 9-May-12 3:14am    
thanks for reply Birajdar,i tried like that, when i click on the button window closing i want to show window if an error came........
bbirajdar 9-May-12 10:46am    
So you can use a 'alert' or 'window.open' in that case where you want to show the error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900