1

I've successfully used the following script in NewForm.aspx to hide a column 'Date SharePoint checked' when another column 'Check SharePoint?' is set to 'No'.

When I open the same list item in EditForm.aspx or ListForm.aspx I need it to also hide the column. The script works when the Yes/No column is changed, but I need it to work on the existing value when the item is opened. Can the existing script be modified for that? Thanks.

//Show/hide columns based on Drop Down Selection
$("select[title='Check SharePoint?']").change(function() {
if ($("select[title='Check SharePoint?']").val() != "Yes")
{
$('nobr:contains("Date SharePoint Checked")').closest('tr').hide();
}
else
{
$('nobr:contains("Date SharePoint Checked")').closest('tr').show();
}
});

2 Answers 2

0

Try adding below code on your EditForm.aspx page:

$(document).ready(function() {
    if ($("select[title='Check SharePoint?']").val() != "Yes") {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').hide();
    }
    else {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').show();
    }
});

OR*:

function runAfterPageLoads(){
    if ($("select[title='Check SharePoint?']").val() != "Yes") {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').hide();
    }
    else {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').show();
    }
}
_spBodyOnLoadFunctionNames.push("runAfterPageLoads");

If this doesn't work then try one of the solutions given in my answer in below link:

Run Javascript after page loads

0

Use $(document).ready function to check the column value and hide another column, here is the final modified code snippet for your reference:

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    if ($("select[title='Check SharePoint?']").val() != "Yes") {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').hide();
    }
    else {
        $('nobr:contains("Date SharePoint Checked")').closest('tr').show();
    }
    
    
        $("select[title='Check SharePoint?']").change(function() {
            if ($("select[title='Check SharePoint?']").val() != 'Yes')
            {
            $("nobr:contains('Date SharePoint Checked')").closest("tr").hide();
            }
            else
            {
            $("nobr:contains('Date SharePoint Checked')").closest("tr").show();
            }
        });

});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.