Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table which contains a drop down list and 2 text boxes and a button on that row use to save a row record now i want to restrict the user to save null records into data base, using jquery i am checking values but its not working.

What I have tried:

JavaScript
$('body').on('click', '.addInvoice', function () {
                debugger;
                var adddetailbtn = $(this);
                if ($("form").valid()) {

                    var clientID = $(this).parents('tr').find('[id*=ClientID]').val()
                    var date = $(this).parents('tr').find('[id*=Date]').val()
                    var amount = $(this).parents('tr').find('[id*=Amount]').val()
                    var ClientComplainID = $(this).attr('_id')//$('#ClientComplainID').val();
                    ClientComplainID = ClientComplainID == undefined ? 0 : ClientComplainID;

                    if (clientID == "" || clientID == null && date == "" || date == null && amount == "" || amount == null) {
                        if (clientID == "" || clientID == null) {
                            $('#Client').text("must select client")
                        }
                        if (clientID == "" || clientID == null) {
                            $('#Date').text("must select date")
                        }
                        if (clientID == "" || clientID == null) {
                            $('#Amount').text("must select amount")
                        }
                    }
                    else { 

                    var Complainid = $("#ComplainID").val();
                    Complainid = Complainid == undefined || Complainid == "" ? 0 : Complainid;
                    //if (ClientComplainID == undefined) {
                    //    ClientComplainID = 0;
                    //}
                    var data = new FormData($("#frmComplain")[0]);
                    data.append("clientID", clientID);
                    data.append("date", date);
                    data.append("amount", amount);
                    data.append("Complainid", Complainid);
                    data.append("ClientComplainID", ClientComplainID);
                    



                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/Complain/SaveClientInfo")',

                        datatype: "JSON",
                        processData: false,
                        contentType: false,
                        data: data,
                        success: function (data) {
                            debugger;
                            $('#myTbl').html(data);
                            $('#myModal').modal('show');
                            $(adddetailbtn).attr("_id", $(data).find("#ClientComplainID").val());
                        }
                     });

                    }


                 
            }

            else { return false; }
Posted
Updated 20-Apr-17 22:25pm
v2

1 solution

try

$('#Client,#Date,#Amount').text("");
var isValid = true;
    if (clientID == "" || clientID == null) {
        $('#Client').text("must select client");
        isValid = false;
    }
    if (clientID == "" || clientID == null) {
        $('#Date').text("must select date")
        isValid = false;
    }
    if (clientID == "" || clientID == null) {
        $('#Amount').text("must select amount")
        isValid = false;
    }
    if (isValid) {
        // ajax call
    }
    else
        return false;
   

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