Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:35:22+00:00 2026-05-23T08:35:22+00:00

Has anyone ever experienced this situation? I’ve got a JQuery method that works well

  • 0

Has anyone ever experienced this situation?

I’ve got a JQuery method that works well with selects and checkboxes AS LONG as they are positioned as predetermined (select => checkbox). But the moment I position them the other way around (checkbox <= select) the “effects” of the method on the checkboxes “change places” somehow (a checkbox that should be disabled is not and one that should be enabled is instead disabled). Also, it doesn’t happen in all cases but rather “by pairs” (when a checkbox should be enabled and is not, the following checkbox is enabled when it shouldn’t and then it reverts to normalcy again until the next time the same thing happens).

I am talking about two large divs with float left & right, each containg a series of children divs with a select and a checkbox inside each child div; selects and checkboxes are not “inverted” in the left large div and are inverted in the right large div.

I should remark that this affects the “inverted” checkboxes only. Selects work as expected no matter how they are positioned.

I,ve tried to separate (by creating the proper JQuery selector) those conflicting checkboxes by id of parent div, by select class, etc. to no avail. Everything works well if all elements are positioned like selects to the left and checkboxes to the right.

The code:

<div>

    <div style="width: 49.5%; float: left;">

        <div>
            <select id="select_01"> 
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>
            </select>
            <input id="check_box_01" type="checkbox" />
        </div>

        <div>
            <select id="select_02"> 
                <option value="first" selected="selected">First option</option> 
                <option value="">Whatever as prompt...</option> 
            </select>
            <input id="check_box_02" type="checkbox" />
        </div>

        <div>
            <select id="select_03">
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>                    
            </select>
            <input id="check_box_03" type="checkbox" />
        </div>

        <div>
            <select id="select_04">
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>                    
            </select>
            <input id="check_box_04" type="checkbox" />
        </div>

    </div>

    <div style="width: 49.5%; float: right;">

        <div>
            <input id="check_box_05" type="checkbox" />
            <select id="select_05"> 
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>
            </select>
        </div>

        <div style="border: 1px solid red;">
            <input id="check_box_06" type="checkbox" />
            <select id="select_06"> 
                <option value="first" selected="selected">First option</option>
                <option value="">Whatever as prompt...</option> 
            </select>
        </div>

        <div style="border: 1px solid red;">
            <input id="check_box_07" type="checkbox" />
            <select id="select_07"> 
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>
            </select>
        </div>

        <div>
            <input id="check_box_08" type="checkbox" />
            <select id="select_08"> 
                <option value="">Whatever as prompt...</option> 
                <option value="first">First option</option>
            </select>
        </div>

    </div>

</div>

$(document).ready(function() {
    $("select, :checkbox").each(function() {
        if ($(this).is("select")) {
            mySelectId = $("#" + $(this).attr("id"));
            if (mySelectId.attr("value") === "") {
                mySelectId.css({
                    "background": "#D3D3D3"
                });
            }
        } else if ($(this).is(":checkbox")) {
            myCheckboxId = $("#" + $(this).attr("id"));
            if (mySelectId.attr("value") === "") {
                myCheckboxId.attr("disabled", "disabled");
            }
        }
    });
});

And the problem:

screencapture of the problem

You can interact with the code if you wish: http://jsfiddle.net/CarlosPF/Unbsb/

Any help or suggestions will be greatly appreciated. Thanks in advance to you all.

By the way, what the method does is to darken those selects with nothing selected and disable its corresponding checkboxes (or viceversa)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:35:23+00:00Added an answer on May 23, 2026 at 8:35 am

    mySelectId in your else if clause if out of scope.

    the offending code (pseudo form):

        if (select) {
            mySelectId = "some value"
            }
        } else if (checkbox) {
            if (mySelectId.attr("value") === "") { // <-- mySelectID was never properly set!
                //do whatever
            }
        }
    

    EDIT:
    I’ve changed your jQuery:

    $(document).ready(function() {
        $("select").each(function() {
            if ( $(this).val() === "") {
                $(this).css("background-color", "#d3d3d3");
                $(this).siblings(":checkbox").attr("disabled", "disabled"); 
            }   
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps this is a ridiculous question. Has anyone ever experienced a situation where R
Has anyone ever experienced this ? VS 2008 bug http://files.sauliaus.info/vs2008_bug.png Out of the blue,
Has anyone ever launched cloud-based apps / websites that use a local SQLite DB
Has anyone seen this very strange behaviour before? I've got a solution whith 70
Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?
Has anyone ever heard of a UNIX shell written in a reasonable language, like
Has anyone ever done work to get Ruby to do continuations (like Seaside on
Has anyone ever tried, or had any success at getting Wascana (Eclipse CDT +
Has anyone ever seen the storage class auto explicitly used in C/C++? If so,
Has anyone ever used the Bridge pattern in a real world application? If so,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.