Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How to re-enable disabled dropdowns disabled by selecting value from the initial dropdown

GOAL: Create a script that disables other dropdown select lists using the same class ("selectClass") if an item is selected from one of the dropdowns selects. Or, if the item is unselected, then all dropdown selects became selectable again to allow for people who change their minds/didn't understand at first what would happen.

The goal is to allow a user to only be able to select one item (total) from X amount of lists possible - you can have apples, or oranges, or pairs, but you can only have one type of fruit (for this example)

PROBLEM: I am unable to get the list to be selectable again after a selection has been made even if the default no value option is selected.

EFFORTS: I've put a few hours into this script and have gotten as far as I can it seems. I've looked through Stack, Googled, and searched other forums and bulletin boards, and Reddit. I've found some things I hoped would help me reach my goal, but I wasn't able to understand them due to my newb-ness, or they weren't applicable enough to help me reach my goal. I have run the script through javascript validators to make sure I've got the syntax correct, etc. I've managed to get pretty far towards my goal (goal was just deactivating the other dropdowns), but I'd like to make the user experience top-notch, and to me that means allowing for a sure to change their mind without needing to reload a page and lose all their unsubmitted data.

THE ASK: I am hoping for help and guidance to make everything re-selectable again by unselecting the selected item from the list that disabled the other dropdown selects; The lists will be generated dynamically.

THE CODE:

<select class="selectClass">
    <option  value="">Apples</option>
    <option value="1">1 Apple</option>
    <option value="2">2 Apple</option>
    <option value="3">3 Apple</option>
</select>
<select class="selectClass">
    <option  value="">Oranges</option>
    <option value="1">1 Orange</option>
    <option value="2">2 Orange</option>
    <option value="3">3 Orange</option>
</select>
<select class="selectClass">
    <option value="" >Pears</option>
    <option value="1">1 Pears</option>
    <option value="2">2 Pears</option>
    <option value="3">3 Pears</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $(function () {
        $(".selectClass").on('change', function () {
            $(".selectClass").not($(this)).prop("disabled", "disabled")
        })
    })
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$(function () {
    $(".selectClass").on('change', function (e) {
        if (e.target.value === "") $(".selectClass").not($(this)).attr("disabled", false)
        else $(".selectClass").not($(this)).prop("disabled", "disabled")
    })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="selectClass">
    <option  value="">Apples</option>
    <option value="1">1 Apple</option>
    <option value="2">2 Apple</option>
    <option value="3">3 Apple</option>
</select>
<select class="selectClass">
    <option  value="">Oranges</option>
    <option value="1">1 Orange</option>
    <option value="2">2 Orange</option>
    <option value="3">3 Orange</option>
</select>
<select class="selectClass">
    <option value="" >Pears</option>
    <option value="1">1 Pears</option>
    <option value="2">2 Pears</option>
    <option value="3">3 Pears</option>
</select>

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!