Solved

Help with check box disabled state

Posted on 2011-09-25
4
196 Views
Last Modified: 2012-05-12
Hey all,

Need help with script that removes the disabled state of a button when a checkbox is clicked. The default state of the checkbox is unchecked and the default state of the button is disabled.

When the user checks the box the disabled state and disabled class is removed.

<input type="checkbox" name="term" value="Bike" />

<button type="button" disabled="disabled" class="disabled">Click Me!</button>

The framework Im using is jQuery. Thanks for your help.



0
Comment
Question by:yando18
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36596307
test page : http://jsfiddle.net/35h5r/1/

$(document).ready(function() {
    
$(":checkbox[name='term'][value='Bike']").click(function() {
    if( $(this).is(":checked") ) {
        $("button").removeAttr("disabled");
    }
    else {
        $("button").attr("disabled",true);
    }
})
    
    })

Open in new window


replace the selector $("button") if you give an ID to your button
0
 

Author Comment

by:yando18
ID: 36596385
must also remove the class disabled
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36596393
updated : http://jsfiddle.net/35h5r/2/
$(document).ready(function() {
    
$(":checkbox[name='term'][value='Bike']").click(function() {
    if( $(this).is(":checked") ) {
        $("button").removeAttr("disabled").removeClass("disabled");
    }
    else {
        $("button").attr("disabled",true).addClass("disabled");
    }
})
    
    })

Open in new window

0
 

Author Comment

by:yando18
ID: 36596400
That should do it thanks
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
youtube blocking politics 4 55
xss alert in domino url 9 33
jQuery force form POST 7 45
Designing forms 3 17
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
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)

856 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