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

  • Home
  • SEARCH
  • 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 3398262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:37:41+00:00 2026-05-18T04:37:41+00:00

I made this function and need some help sorting out the logic flow. It

  • 0

I made this function and need some help sorting out the logic flow. It works… to some degree and just need help weeding out the bugs.

My HTML:

<span style="float: left;"><input type="checkbox" id="top" name="position" value="top" />&nbsp;Top&nbsp;&nbsp;</span>
<span style="float: left;"><input type="checkbox" id="bottom" name="position" value="bottom" />&nbsp;Bottom&nbsp;&nbsp;</span>
<span style="float: left;"><input type="checkbox" id="left" name="position" value="left" />&nbsp;Left&nbsp;&nbsp;</span>
<span style="float: left;"><input type="checkbox" id="center" name="position" value="center" />&nbsp;Center&nbsp;&nbsp;</span>
<span style="float: left;"><input type="checkbox" id="right" name="position" value="right" />&nbsp;Right</span>

And here is my jQuery function:

/// Bind Position value to 'CSS : BackgroundPosition' ///       
var $positions;

function bgpos(){
    var pos = $positions.map(function() {
        if($('#top').attr('checked') == true)
            $('#bottom').attr('disabled', true);
        else
            $('#bottom').attr('disabled', false);

        if($('#bottom').attr('checked') == true)
            $('#top').attr('disabled', true);
        else
            $('#top').attr('disabled', false);

        if($('#left').attr('checked') == true){
            $('#right').attr('disabled', true);
            $('#center').attr('disabled', true);
        }else{
            $('#right').attr('disabled', false);
            $('#center').attr('disabled', false);
        }

        if($('#right').attr('checked') == true){
            $('#left').attr('disabled', true);
            $('#center').attr('disabled', true);
        }else{
        $('#left').attr('disabled', false);
        $('#center').attr('disabled', false);
        }

        if(this.checked) return this.id;
    }).get().join(' ');
    //$('#queue').html(pos);
    $('#topHeader').css({'backgroundPosition' : pos});
}

$(function() {
    $positions = $("form#frm_look_and_feel input[name='position']").change(bgpos);
});

And here is my jsFiddle if anyone is interested:

http://jsfiddle.net/s2xi/nWT5J/2/

One problem I have is that when you click on ‘Top’ it doesn’t disable ‘Bottom’ but when I click on ‘Bottom’ it does disable ‘Top’ and the same problem occurs when I click on ‘Left’, My ‘Center’ doesn’t get disabled, but clicking on ‘Right’ disables ‘Left’ and ‘Center’ like it should.

  • 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-18T04:37:41+00:00Added an answer on May 18, 2026 at 4:37 am

    I didn’t have a problem with your top/bottom, but the other issues are because #center‘s state is always determined by the state of #right, since there’s an if/else around it…regardless of what #left just set it to.

    Also .map() runs for every element, you don’t want this logic inside there, take it outside like this:

    function bgpos(){
        bottom.disabled = top.checked;
        top.disabled = bottom.checked;
        left.disabled = center.checked || right.checked;
        center.disabled = left.checked || right.checked;
        right.disabled = left.checked || center.checked;
        var pos = $positions.map(function() {
            if(this.checked) return this.id;
        }).get().join(' ');
        $('#topHeader').css({'backgroundPosition' : pos});
        $('#output').html(pos);
    }
    

    In this case those variables are the DOM elements directly just because it looks cleaner to me (and is much faster, if it matters). You can test it out here.


    As an alternative, consider just using radio buttons for each group, like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help improving this function I made for parsing the links in
I made this and needed some help tweaking it so that it gives the
I'm new to iPhone dev and need some help with adding subViews. I have
I've made this decorator, which results in an infinite redirect loop. The problem is
Since I'm sure many people have different standard, I've made this post a community
I wonder if someone knows if there is a pre-made solution for this: I
I have roughly the following code. Could this be made nicer or more efficient?
This is something that made me doubt for a while so I thought it
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
As made clear in update 3 on this answer , this notation: var hash

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.