Question

I am looking for a jQuery script to conditionally disable two field types:

  1. Disable a text field if it is not blank and
  2. Disable a number field once it is non zero.

I see many posts on disabling People Pickers and Date fields, but not the above.

Thank you for you help.

Was it helpful?

Solution

Assuming you want to disable the form fields on Edit form.

For Single line of text field: Consider column name is - Title

$(document).ready(function(){
    if($("input[title^='Title']").val()) {
        $("input[title^='Title']").attr("disabled", "disabled");
    
        //$("input[title^='Title']").attr("readonly", "readonly");
    }
});

For Number field: Consider column name is - Content Amount

$(document).ready(function(){
    if($("input[title^='Content Amount']").val() != "0") {
        $("input[title^='Content Amount']").attr("disabled", "disabled");
        
        //$("input[title^='Content Amount']").attr("readonly", "readonly");
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top