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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:19:26+00:00 2026-05-28T16:19:26+00:00

I have this piece of code for select option: <select class=select-box name=select-choice-month id=select-locations> <option

  • 0

I have this piece of code for select option:

<select class="select-box" name="select-choice-month" id="select-locations">
  <option id="1">Select Region</option>
  <option id="2" value="eu">Europe</option>
  <option id="3" value="nam">North America</option>
  <option id="4" value="sam">Latin America</option>
  <option id="5" value="aspa">Asia/Pacific</option>
</select>

On select change I already have to change its background like this (displaying or hiding specific div):

$('#select-locations').change(function() {
    $('#form1, #form2, #form3, #form4, #form5').hide();
    $('#form' + $(this).find('option:selected').attr('id')).show();
});

But, now I have mini navigation which is also displaying or hiding same div’s

<div id="map-menu">
    <a href="#" id="3">North America</a>
    <a href="#" id="4">Latin America</a>
    <a href="#" id="5">Asia/Pacific</a>
</div><!-- end of map-menu -->

Jquery for this:

$('#map-menu a').click(function() {
    $('#form1, #form2, #form3, #form4, #form5').hide();
    $('#form' + $(this).attr('id')).show();
});

How can I achieve when anchor is clicked and div is changed to change output (name) of selected option also? In first example that is working, but when I am changing it through anchors it doesnt work …

Tnx for any answers

  • 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-28T16:19:27+00:00Added an answer on May 28, 2026 at 4:19 pm

    If I read your question correctly then I think the following should solve your problem and reduce code repetition.

    $('#map-menu a').click(function() {
        $('#select-locations').val(this.id).change();
    });
    

    It will listen for a click on the as and then set the value of the select list to the clicked id. Once this is complete it will trigger the change event on the select list causing your change listener to be triggered.

    Also a note on your ids they should not just be a number:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
    followed by any number of letters, digits ([0-9]), hyphens (“-“),
    underscores (“_”), colons (“:”), and periods (“.”).

    Source: https://stackoverflow.com/a/703790/461813

    Updated work around from comments

    If you want to use your current HTML then it would be something like this:

    $('#map-menu a').click(function() {
        var select = $('#select-locations');
        var option_to_select = $('option[id="' + this.id + '"]', select);
        select.val(option_to_select.val()).change();
    });
    

    But it should be noted that your code currently does not have unique ids so I suggest you namespace them like:

    select_option_1
    anchor_option_1
    

    Then the above code would become:

    $('#map-menu a').click(function() {
        var option_id = this.id.replace('anchor', 'select');
        var select = $('#select-locations');
        var option_to_select = $('option[id="' + option_id + '"]', select);
        select.val(option_to_select.val()).change();
    });
    

    And here it is as a jsFiddle you can run: http://jsfiddle.net/6tHnj/

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

Sidebar

Related Questions

I have the following code: <select name=to class=combo value=' <?php if(isset($_POST['reply'])) { echo <option
I have this piece of code: <li class=selected><a href=/AmIACandidate.html>Am I a Candidate?</a></li> I need
Let's say I have this HTML: <select id='list'> <option value='1'>First</option> <option value='2'>Second</option> <option value='3'>Third
I have this piece of code (summarized)... AnsiString working(AnsiString format,...) { va_list argptr; AnsiString
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this piece of code: var myObj = function () { this.complex =
I have this piece of code I'm trying to get to display but no
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated

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.