1

I have a page with many panels. each panel will have around 5 textboxes. I need to disable all the textboxes which are empty when the page is loaded. Want to acieve this using JQuery. Can somebody help me on this?

2 Answers 2

3

This should do it:

$(function(){
 $('input[type="text"]').each(function(){
   if ($(this).val() === '') {
     $(this).attr('disabled', 'disabled');
   }
 });
});

If you have applied some class to your textboxes, you can also do:

$(function(){
 $('.class_name').each(function(){
   if ($(this).val() === '') {
     $(this).attr('disabled', 'disabled');
   }
 });
});
Sign up to request clarification or add additional context in comments.

Comments

1
var empties = $('input:text').filter(function() {
    return this.value == '';   // If the value of the input is empty, 
});                            //    add it to the collection

empties.attr('disabled','disabled');   // Then disable the collection of empties

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.