none
JQuery/JavaScript - On NewForm.aspx how to make a field mandatory by JavaScript? RRS feed

  • Question

  • Hi there

    JQuery/JavaScript - On NewForm.aspx how to make a field mandatory by JavaScript?

    Thanks.

    Thursday, April 20, 2017 9:37 PM

Answers

  • Hi,

    You can check the value of a field in PreSave function as shown below:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
     function PreSaveAction()
     { 
     var name=$("input[title='Name']").val(); //change the "Name" with your field name
     if(name=="")
     {        
       alert("Please enter the name");          
       return false;
     }
     else
     {
       return true;
     }
    }
    </script>


    Regards, Sathiya

    • Marked as answer by ran009 Friday, April 21, 2017 8:36 PM
    Friday, April 21, 2017 5:13 AM