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

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 Nov 3 '20 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 Feb 25 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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