$(document).ready(function() not working SharePoint 2013/2016 list form

This SharePoint 2013 tutorial explains, how to solve $(document).ready(function() not working SharePoint 2013 list form error which comes in SharePoint 2013/2016 list forms like the new form, edit form or display form.

Here user wants to hide a field in a new form without custom c#.net code in SharePoint 2013/2016. I have tried with jquery and was trying to hide the field row in newform.aspx. But document.ready() is firing in newform.aspx.

Code snippet I was trying to use is:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("input[title*='FirstName']").val("Krishna.Vandanapu");
var field = $("input[title*='FirstName']"); // The * in title is needed because SharePoint 2013 uses "Required Field" on required fields.
field.parent().parent().parent().hide();
});
</script>

In the above code block I was trying to hide the row of FirstName field in the below screen with a default value as “Krishna.Vandanapu”. Since it is a mandatory field I set the default value.

Document.ready() not working in list new form-2013
Document.ready() not working in list new form-2013

The issue with the above code is I was missing the jquery reference library inclusion.

$(document).ready(function() not working SharePoint 2013 list form

We have to add the ajax library file http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js in the script to fire the $(document).ready function.

The final code will be as follows:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
alert("Krishna");
$("input[title*=Title]").val( "Title Value-1" );
$("input[title*='FirstName']").val("Krishna.Vandanapu"); //The * in title is needed because SharePoint 2013 uses "Required Field" on required fields.
var field = $("input[title*='FirstName']");
field.parent().parent().parent().hide();
});
</script>

The output will be as follows:

Document.ready() not working in list new form online
$(document).ready(function() not working SharePoint 2013 list form

You may like following SharePoint jQuery tutorials:

Hope this SharePoint 2013 tutorial helps to resolve $(document).ready(function() not working SharePoint 2013 list form.

>