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 8740913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:12:55+00:00 2026-06-13T11:12:55+00:00

I have a form with a bunch of dropdown options that I’m dressing up

  • 0

I have a form with a bunch of dropdown options that I’m dressing up by allowing the option to be selected by clicking links and (in the future, images) instead of using the actual dropdown. There are a lot of dropdowns and most all will repeat the same basic idea, and some will literally repeat just with different variables. Here’s the HTML for one of those.

<tr class="box1">
  <td>
    <select id="cimy_uef_7">
      <option value="Boy">Boy</option>
      <option value="Girl">Girl</option>
    </select>
  </td>
</tr>

Then the corresponding fancier links to click that will select the corresponding option in the dropdown.

<div id="genderBox1">
  <div class="gender"><a class="boy" href="">Boy</a></div>
  <div class="gender"><a class="girl" href="">Girl</a></div>
</div>

So, when you click the link “Boy” it will select the corresponding dropdown value “Boy” There are going to be multiple Box#, so I can just repeat the jQuery each time with the new variables, but there’s surely a shorter way. Here’s the jQuery that makes it work.

//Box1 Gender
  var Gender1 = $('select#cimy_uef_7');
  var Boy1 = $("#genderBox1 .gender a.boy");
  var Girl1 = $("#genderBox1 .gender a.girl");

//On Page Load - Check Gender Box 1 Selection and addClass to corresponding div a
  if ( $(Gender1).val() == "Boy" ) {
    $(Boy1).addClass("selected");
    } else {
    $(Boy1).removeClass("selected");
    }

  if ( $(Gender1).val() == "Girl" ) {
    $(Girl1).addClass("selected");
    } else {
    $(Girl1).removeClass("selected");
    }

  //On Click - Change Gender Box 1 select based on image click
  $(Boy1).click(function(event) {
    event.preventDefault();
    $(this).addClass("selected");
    $(Gender1).val("Boy");
    $(Girl1).removeClass("selected");
  });

  $(Girl1).click(function(event) {
    event.preventDefault();
    $(this).addClass("selected");
    $(Gender1).val("Girl");
    $(Boy1).removeClass("selected");
  });

My thought for shortening it was to just have a list of variables for each box and cycle through the numbers- 1,2,3,4 and have the jQuery grab the same # for each variable, but I can’t figure out a way to do it.

Let me know if there’s anything else I can provide to make the question better. This is my best idea for shortening this code, as I’m still very much a beginner at jQuery, but I’m positive there are much better ideas out there, so feel free to recommend a better path if you see it 🙂

  • 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-06-13T11:12:56+00:00Added an answer on June 13, 2026 at 11:12 am

    Here is a generalized solution.

    Construct your HTML as follows, ensuring that the text contained by the anchors (“Boy” / “Girl”) exactly matches the values of the corresponding menu options.

    HTML:

    <tr class="box1">
      <td>
        <select class="remoteSelectable" id="cimy_uef_7">
          <option value="Boy">Boy</option>
          <option value="Girl">Girl</option>
        </select>
      </td>
    </tr>
    
    <div id="genderBox1" class="remoteSelector" data-menu="cimy_uef_7">
      <div class="gender"><a href="">Boy</a></div>
      <div class="gender"><a href="">Girl</a></div>
    </div>
    

    javascript:

    //force select menus to same value as clicked remote link
    $(".remoteSelector a").on('click', function(e) {
        e.preventDefault();
        var $this = $(this).addClass('selected'),
            $container = $this.closest(".remoteSelector");
        $container.find("a").not(this).removeClass('selected');
        $('#' + $container.data('menu')).val($this.text());
    });
    
    //force remote links to reflect value of selected menu option
    $(".remoteSelectable").on('change', function() {
        var $this = $(this);
        $(".remoteSelector").filter(function() {
            return $(this).data('menu') == $this.attr('id');
        }).find("a").removeClass('selected').filter(function() {
            return $(this).text() == $this.val();
        }).addClass('selected');
    }).trigger('change');
    

    DEMO

    Notes :

    • The ‘change’ handler is triggered immediately to force the correct remote link to be styled ‘selected’.

    • The select menus may be hidden by moving them off-screen with absolute positioning, or with display:none if they are not part of a form that’s going to be submitted.

    If at any point (after the handlers are attached) the menus need to be changed programatically then do so as follows to ensure the corresponding remote link is kept up to date :

    $("#cimy_uef_7").val('Girl').trigger('change');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that allows me to upload images and bunch of text
i have a windows form that contains a bunch of textboxes. I need a
I have a HTML form, that contains a bunch of text inputs and one
I have an asp.net form with bunch of sections that can be expanded/collapsed and
I have a form that will be populated by a bunch of information from
I have a form that contains a bunch of checkboxes. Before submitting the form,
Let's say I have a form that contains a whole bunch of check boxes
I have a long-form data that represents a bunch of different configurations of different
I have a form with a bunch of checkboxes, and a hidden field that
I have a web form with a bunch of checkboxes; when a specific box

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.