Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<script type="text/javascript">
    $(document).ready(function () {



        $("#btnSave").click(function () {
            var empObj = {
                SERIALNO: $('#txtSerialNo').val(),
                CARDSERIALNO: $('#txtCardSNO').val(),
                FAULTCODE1: $('#txtFaultcode').val(),
                DATE_RECEIVED: $('#txtDateReceived').val(),
                PONO: $('#txtPONO').val(),
                CARDPARTNO: $('#txtCardPartNo').val(),

            };

         if (!$("#myform").valid())
            {
            return false;
            }

            $.ajax({
                url: "/Scanning/Postprescaning",
                data: JSON.stringify(empObj),
                type: "POST",
                contentType: "application/json;charset=utf-8",




         success: function (result,data)
            {
             alert("DATA SAVED !!");
                },
                error: function (errormessage) {
                    alert(errormessage.responseText);
                }

            });
        });
    });
        </script>


What I have tried:

<script type="text/javascript">
    $(document).ready(function () {



        $("#btnSave").click(function () {
            var empObj = {
                SERIALNO: $('#txtSerialNo').val(),
                CARDSERIALNO: $('#txtCardSNO').val(),
                FAULTCODE1: $('#txtFaultcode').val(),
                DATE_RECEIVED: $('#txtDateReceived').val(),
                PONO: $('#txtPONO').val(),
                CARDPARTNO: $('#txtCardPartNo').val(),

            };

         if (!$("#myform").valid())
            {
            return false;
            }

            $.ajax({
                url: "/Scanning/Postprescaning",
                data: JSON.stringify(empObj),
                type: "POST",
                contentType: "application/json;charset=utf-8",




         success: function (result,data)
            {
             alert("DATA SAVED !!");
                },
                error: function (errormessage) {
                    alert(errormessage.responseText);
                }

            });
        });
    });
        </script>
Posted
Updated 22-Jan-19 1:24am

1 solution

Make sure you've included the jQuery Validation plugin[^] scripts, to ensure that the .valid() call will work.

Add the required attribute[^] to any input, textarea, or select elements which cannot be blank.

Optionally, add any other validation attributes you require:
Form data validation | MDN[^]
 
Share this answer
 
Comments
Member 10194266 23-Jan-19 7:32am    
Thanks Richard its working

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