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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:19:12+00:00 2026-05-27T07:19:12+00:00

I have a select in a form with a button next to it. Below

  • 0

I have a select in a form with a button next to it. Below is an unknown quantity of other select fields.

<select class="offer_1 value_source" name="xnamex">
    <option value="">Please Select</option>
    <option value="xxxxxxx">Text</option>
</select>
<button class="copy_select offer_1" type="button" name="Copy" value="">Copy Down</button>
<select class="offer_1" name="xnamex">
    <option value="">Please Select</option>
    <option value="xxxxxxx">Text</option>
</select>
<!-- unknown quantity of selects follow -->

I am grouping the select fields and button together via the class offer_{number}

I want to copy the selected value from the one select with the class value_source to all other selects with the same class (offer_{number}).

Here is my current code:

$(document).ready(function() {
    $('.copy_select').click(function() {
        attr_class = $(this).attr('class');
        attr_class = attr_class.replace('copy_select ', '.');
        $(attr_class).val($(attr_class + ' value_source').val());
        alert(attr_class);
    });
});

All selects remain unselected and my copy_source get reset to unselected.

What am I doing wrong?

Also, how would I check that the select has a value set and throw up an alert() if not?

Many, many thanks for your time 🙂

  • 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-27T07:19:13+00:00Added an answer on May 27, 2026 at 7:19 am

    Not sure what’s wrong with your original example, this does what I think you want to do. That is, when the button is clicked, select the current value from select.offer_1.value_source in all other selects with the class offer_1; and not to selects with the class offer_2 which will be handled with another button.

    JavaScript

    $('.copy_select').click(function() {
        $selects = $($(this).data('selects'));
        $source = $selects.filter('.value_source');
        $copies = $selects.not('.value_source');
        console.log($selects);
        console.log($source);
        console.log($copies);
        console.log($source.val());
        $copies.val($source.val());
    })
    

    HTML

    <select class="offer_1 value_source" name="xnamex">
        <option value="">Please Select</option>
        <option value="a">Text</option>
        <option value="b">Foo</option>
        <option value="c">Bar</option>
    </select>
    <button class="copy_select" data-selects='.offer_1' type="button" name="Copy" value="">Copy Down</button>
    <select class="offer_1" name="xnamex">
        <option value="">Please Select</option>
        <option value="a">Text</option>
        <option value="b">Foo</option>
        <option value="c">Bar</option>
    </select>
    

    (I’m using a data attribute on the <button> to associate the button with the <select>s because data attributes are awesome and parsing CSS class strings isn’t.)

    Obligatory jsFiddle example.

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

Sidebar

Related Questions

I have... a dynamic populated select box several input boxes a submit button form
The select form component in grails can have the form: <g:select name=user.age from=${0..59} value=${age}
i have following filteringselect: <select name=v dojoType=dijit.form.FilteringSelect valueList=v id=v value=0><option value=></option><option value=0>0-test</option><option value=1>1-test2/option><option value=2>2-test3</option><option
I have A ListView and and delete button on a Form I can select
I have following html. <fieldset id=fieldset-step_3> <input type=text value=2 id=rule_form-lead_time name=rule_form[lead_time]> <select class=w50 id=rule_form-operator
I have a select form element with 5 options. If option 2 is selected
I am attempting to have mechanize select a form from a page, but the
I have some problems sending an id though jquery. I have a form select
I have a html form which have a select list box from which you
I have a select list I've created in a form alter, however, when I

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.