Solved

Help with check box disabled state

Posted on 2011-09-25
4
199 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
[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
  • 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

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to dynamically set the form action using jQuery.

628 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