We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Vaildation in aspx page using javascript

 i pasted my code below ,getting  error on button click   Uncaught TypeError: Cannot read property 'form' of undefined(…) validationSynfucusion.js:2
<form id="custom">
<table>
<tr>
                    <td class="e-leftfields e-textlabel" style="width: 20%;">
                        Job Type:
                    </td>
                    <td style="width: 1%;">
                        <input type="text" id="ddlAddJobType" />
                        <span class="errmsg" ></span>
                    </td>
<td> <button type="submit" onclick="save()" id="btnsubmit" style="float: left; margin-left: 38%;
                margin-bottom: 10px;">
                Save</button></td>
</table> 
</form>
 <script type="text/javascript">
 $.validator.setDefaults({
            ignore: [], // to include hidden input validation   
            errorClass: 'e-validation-error', // to get the error message on jquery validation   
            errorPlacement: function (error, element) {
                $(element).closest("div.control").find("span.errmsg").append(error);
            } // to place error message   
        });   
var JobTypes=[{JobTypeDescription:"job",JobTypeID:"1"}]
   $('#ddlAddJobType').ejDropDownList({
                        dataSource: JobTypes,
                        fields: {
                            text: "JobTypeDescription",
                            value: "JobTypeID"
                        },
                         validationRules: {
                required: true
            },
            validationMessage: {
                required: "Select JobType value"
            },
                        watermarkText: "Select Job Type"
                        //                        htmlAttributes: {
                        //                            style: "border:1px solid red;"
                        //                        }
                    });
function save()
{
 $("custom").valid();
}

</script>

7 Replies

KV Karthikeyan Viswanathan Syncfusion Team November 7, 2016 10:46 AM UTC

Hi Rajiv Gandhi, 
 
  Thanks for contacting Syncfusion support. 
 
  We found that issue. In Save Method, You are selecting a  form element with wrong JQuery selector.  To resolve this issue need to include #  JQuery Selector (#custom) In before of your form ID. 
 
Please use the below code snippet: 
 
Code: 
 
<body> 
 
    <form id="custom"> 
 
        <table> 
            <tr> 
                <td class="e-leftfields e-textlabel" style="width: 20%;">Job Type: 
                </td> 
                <td style="width: 1%;"> 
                    <input type="text" id="ddlAddJobType" /> 
                    <span class="errmsg"></span> 
                </td> 
                <td> 
                    <button type="submit" onclick="save()" id="btnsubmit" style="float: left; margin-left: 38%; margin-bottom: 10px;"> 
                        Save</button></td> 
        </table> 
    </form> 
    <script type="text/javascript"> 
        $.validator.setDefaults({ 
            ignore: [], // to include hidden input validation    
            errorClass: 'e-validation-error', // to get the error message on jquery validation    
            errorPlacement: function (error, element) { 
                $(element).closest("form").append(error); 
            } // to place error message    
        }); 
        var JobTypes = [{ JobTypeDescription: "job", JobTypeID: "1" }] 
        $('#ddlAddJobType').ejDropDownList({ 
            dataSource: JobTypes, 
            fields: { 
                text: "JobTypeDescription", 
                value: "JobTypeID" 
            }, 
            validationRules: { 
                required: true 
           }, 
            validationMessage: { 
                required: "Select JobType value" 
            }, 
            watermarkText: "Select Job Type" 
            //                        htmlAttributes: { 
            //                            style: "border:1px solid red;" 
            //                        } 
        }); 
        function save() { 
             $("#custom").valid(); 
        } 
 
    </script> 
</body> 
</html> 
 
 
 
Regards, 
Karthikeyan V. 



RA rajivgandhi November 7, 2016 12:14 PM UTC

Hi Team
                    Again i'm getting error Uncaught TypeError: Cannot read property 'form' of undefined
    at n.fn.init.valid (validationSynfucusion.js:2:1167)


PO Prince Oliver Syncfusion Team November 8, 2016 09:16 AM UTC

Hi Rajivgandhi,   
  
Thanks for your update.   
  
We could not reproduce the error. Please ensure that you have used the proper JQuery selector for selecting the form, and also check your script references in your sample to find out whether you have included query validation plugin in your sample in a proper order based on dependencies. If the issue still persists, provide us issue reproducing sample.   
  
Regards,   
Prince 



RA rajivgandhi November 11, 2016 05:18 AM UTC

Him Team,
                         send  query validation plugin order 


PO Prince Oliver Syncfusion Team November 11, 2016 10:23 AM UTC

Hi Rajivgandhi,   
  
Thanks for your update.   
  
Refer the jQuery and EJ scripts in following order in your sample.   
  
1.       jQuery script   
2.       jQuery validation script   
3.       EJ web all script   
  
Note: If you are using any other jQuery scripts refer the above EJ script.   


  
Regards,   
Prince 



RA rajivgandhi November 11, 2016 11:15 AM UTC

Hi Team,
                           It's working html page only. not in aspx
                          Please provied content page in aspx .div in a content page


PO Prince Oliver Syncfusion Team November 14, 2016 12:44 PM UTC

Hi Rajivgandhi, 

Sorry for the inconvenience caused. 

Please find the below sample in aspx page. 

Regards, 
Prince

Loader.
Up arrow icon