1

I want to disabled/readonly inputs on some fields in SharePoint 2013 New/Edit forms based on a field's value.

So I manually add <div> around group of <tr>.

<div id='myDiv'> 
<tr>...</tr>
...
<tr>...</tr>
</div>

I have tried two different method, see code below:

$("#myDiv *").prop("disabled", true); 
$("#myDiv").children().prop('disabled',true);

Neither one is working. I have to disabled each field one by one.

Any suggestion for the <div> coding would be appreciated.

Thanks!

1 Answer 1

0

You need to use something like:

$("#myDiv input").prop("disabled", true);
$("#myDiv select").prop("disabled", true);
$("#myDiv textarea").prop("disabled", true);

I tried below and it's working:

<div id='myDiv'>
    <tr>
        <td>Input1</td>
        <td><input type="text"/></td>
    </tr>
    <tr>
        <td>Input2</td>
        <td><input type="text"/></td>
    </tr>
    <tr>
        <td>Input3</td>
        <td><textarea rows="3"></textarea></td>
    </tr>
</div>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#myDiv input").prop("disabled", true);
        $("#myDiv select").prop("disabled", true);
        $("#myDiv textarea").prop("disabled", true);
    });
</script>

CodePen Reference.

Update:

This is working for me on SharePoint list forms as well, see below output and code I have used:

enter image description here

11
  • I used the same js code, it doesn't work. The field is still editable.
    – JJL
    Oct 7, 2019 at 23:40
  • Can you please check the codepen reference... Which is working fine for me. Oct 8, 2019 at 2:36
  • It works on CodePen. Is there any special in Sharepoint 2013? I add '<div>' manually using SPD.
    – JJL
    Oct 9, 2019 at 16:21
  • Try adding breakpoint in document.ready() and check if you are getting the div element using $("#myDiv") Oct 9, 2019 at 16:42
  • Hi Ganesh - I do get div element.
    – JJL
    Oct 9, 2019 at 18:29

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.