0

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.

0

1 Answer 1

1

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");
    }
});
2
  • 1
    Ganesh, thank you!! This is exactly what I was looking for. Have a great day and stay safe.
    – ChasEpes
    Commented Nov 3, 2020 at 14:31
  • Hi Ganesh: Now I need to disable a date field once it is populated. Might you be able to help with this? Thank you!
    – ChasEpes
    Commented Feb 25, 2021 at 15:15

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.