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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:58:11+00:00 2026-06-05T01:58:11+00:00

This originates from my original question . I’m expanding on it. Html select options

  • 0

This originates from my original question. I’m expanding on it.

Html select options

    <select id="1d" name="camp" multiple="multiple">
    <option data-url0="week_1" value="Week 1">30th July</option>
    <option data-url1="week_2" value="Week 2">6th August</option>
    </select>
    <input type="hidden" name="camp_url0" id="1e">
    <input type="hidden" name="camp_url1" id="1f">

Jquery script I’m struggling with.

    $("#1d").on("change", function () {
    var url1 = $(this).children(":selected").data("url0");
    var url2 = $(this).children(":selected").data("url1");
    $("#1e").val(url0);
    $("#1f").val(url1);
});

This code works beautifully (maybe not the cleanest?), except for one important issue. Even though it is a multiple selector, whenever both options are selected, only one option is marked as :selected in DOM, meaning only one data-url{row_id} is being inputted. I need both, if both are selected.

I hope that makes sense. Thanks for your help.

  • 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-05T01:58:12+00:00Added an answer on June 5, 2026 at 1:58 am

    UPD:

    Add some additional “routing” data to the html

    <select id="1d" name="camp" size="5" multiple>
        <option data-url="week_1" data-id="1e" value="Week 1">30th July</option>
        <option data-url="week_2" data-id="1f" value="Week 2">6th August</option>
    </select>
    

    and use it

    $("#1d").on("change", function () {
        $('input[type=hidden]').val('');
    
        $('option:selected', this).each(function() {
            $('#' + $(this).data('id')).val($(this).data('url'))
        })
    })
    

    http://jsfiddle.net/5ctDC/1/

    OLD:

    Just .map it and you will get an array with the data.

    $('option:selected', this).map(function() {
        return $(this).data('url')
    })
    

    ["week_1", "week_2"]

    http://jsfiddle.net/5ctDC/

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

Sidebar

Related Questions

This question originates from a discussion on whether to use SQL ranking functionality or
How can I do something like this in nHibernate: select count(*) from (subquery) It
I'm currently getting this error from an InvalidCastException [A]System.Data.Objects.ObjectResult`1[EDMXAssembly.ServiceStatus] cannot be cast to [B]System.Data.Objects.ObjectResult`1[EDMXAssembly.ServiceStatus].
Also can you please answer this question? how do I get co-ordinates of selected
This is probably a stupid question, but how much of a security risk is
This question is only related to the first parameter in any event handler, that
I understand this may sound like an odd question.. I have a repo on
Does anyone know where Databasic originates from, and any resources that could help me
I assume that there is probably no satisfactory answer to this question, but I
Possible Duplicate: How would I identify if a website originates from a mobile browser?

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.