Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to disable a list box based on a checkbox

Posted on 2013-11-07
4
Medium Priority
?
780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39629863
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
ID: 39629869
thanks for that  ChrisStanyon, thats what I wanted!
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 39629877
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
ID: 39629880
Or even better:
$('#chkAllAccounts').on('change', function(){
    $('#lstClients').prop('disabled', $(this).prop('checked'));
});

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

660 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