• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

79
Views
Disabled attribute not being removed when checkbox is unchecked with jQuery

The script below will add the disabled attribute to other input fields when #alt_hp field is checked, but when I uncheck the field, the disabled attribute does not get removed. I am not that versed in javascript and tried to make sense of other solutions on this site.

<script>
$("#alt_hp").change(function() {
    if ($("input[type=checkbox]").is( ":checked" )) {
        $("#new_displacement").val('')
        $("input#induction, input#heads, input#camshaft, input#turbo, input#boost, input#inc_displacement").prop("checked", false).prop("disabled", true)
    } else {
        $("input#induction, input#heads, input#camshaft, input#turbo, input#boost, input#inc_displacement").prop("disabled", false)
    }
});
</script> 
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just change below line

if ($("input[type=checkbox]").is( ":checked" )) {

to this

if ($(this).is(":checked")) {

Your existing code will always refer to any/all checkbox in the whole html. this refers to the current checkbox/element.

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error