Solved

How to disable a list box based on a checkbox

Posted on 2013-11-07
4
706 Views
Last Modified: 2013-11-07
Hi there

Hope someone can help me out, I need some JQuery code.

If I check a check-box called "chkAllAccounts" it will disable a drop down list box called "lstClients"

If I un-check the same check-box called "chkAllAccounts" it will enable the drop down list box called "lstClients"

Hope this makes sense?

thanks
0
Comment
Question by:mousemat24
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
Something like this will do it:

$('input[name=chkAllAccounts]').change(function() {
    if ($(this).is(':checked')) {
        $('select[name=lstClients]').prop('disabled', 'disabled');
    } else {
        $('select[name=lstClients]').prop('disabled', false);
    }
});

Open in new window

Here's a fiddle to play with:

http://jsfiddle.net/ChrisStanyon/Z4vRG/
0
 

Author Comment

by:mousemat24
Comment Utility
thanks for that  ChrisStanyon, thats what I wanted!
0
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
like this:
$('#chkAllAccounts').on('change', function(){
        $('#lstClients').attr('disabled', $(this).prop('checked'));
});

Open in new window

0
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
Or even better:
$('#chkAllAccounts').on('change', function(){
    $('#lstClients').prop('disabled', $(this).prop('checked'));
});

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now