Solved

How to disable a list box based on a checkbox

Posted on 2013-11-07
4
723 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 43

Accepted Solution

by:
Chris Stanyon earned 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$q.all is slower or not  in  Angularjs 2 22
Ahax pagination 9 33
How do I show metrics with PHP or Javascript 6 34
I'm a Human captcha checkbox 13 23
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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)

828 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