How to populate an html select with another html select dynamically with Jquery

Jessica Mather

I want to take the selected value of this select:

  <td>
        <select name="colourone" id="firstcolour">
        <option>--select--</option>
        <option value="Red">Red</option>
        <option value="Navy">Navy</option>
        <option value="Royal Blue">Royal Blue</option>
        <option value="Purple">Purple</option>
        <option value="Gold">Gold</option>
        <option value="Emerald Green">Emerald Green</option>
        <option value="Maroon">Maroon</option>
        <option value="White">White</option>
        <option value="Black">Black</option>
        </select>

And use jQuery to add the selected value from that select and add it to another select so that it dynamically populates.

This is what I tried:

$(document).add(function(){
    $('#firstcolour').change(function(){
        $('#colouroption').append($("<option>", {"value": listone_value, "text":    listone_value})).insertAfter($('#blksize'));
    });
});
Anoop Joshi

You can use,

$('#firstcolour').change(function() {
  var option = $("<option>", {
    "value": $(this).val(),
    "text": $(this).find("option:selected").text()
  });
  $('#colouroption').append(option);
});

this will add the new option as the last one.

If you want to add the newly created option as the first one, then use prepend()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery - How to populate dropdown/select/combobox dynamically?

From Dev

Parse .txt file to populate html select with jQuery

From Dev

How to HTML select in jQuery

From Dev

Dynamically add html select onClick of another select box option

From Dev

How to populate dependant select menus dynamically using jQuery, PHP and MySQL?

From Dev

php html form select option to populate text field jquery

From Dev

Select on Change will change another select html javascript or jquery

From Dev

Select on Change will change another select html javascript or jquery

From Dev

How to dynamically preset/select the value of a html select object using Django?

From Dev

jQuery variable (select in html)

From Dev

JQuery to populate select list based on another select list

From Dev

How to select the nth HTML row in jQuery

From Dev

How to set text a select html with jquery?

From Dev

How to select html tag of particular index in jquery

From Dev

How to select html elements using jQuery in Phantomjs?

From Dev

How to add and select an element in html using jquery

From Dev

populate a HTML select in form using Javascript

From Dev

Javascript looping through an object to populate an HTML select

From Dev

Javascript looping through an object to populate an HTML select

From Dev

How to select <select> elements with no html in them through JQuery

From Dev

Populate a dropdown by another select

From Dev

How do I dynamically query the DB based on HTML select option?

From Dev

How to populate a select box with the selected values of another select box

From Dev

How do i populate a select with a db call based on another select

From Dev

Populate select elements dynamically from json data file using jquery

From Dev

How do I populate an html text input field based on an html select option

From Dev

how to populate a select element using jquery?

From Dev

How to populate bootstrap multi select using jQuery

From Dev

Populate items into SELECT with Jquery

Related Related

  1. 1

    jquery - How to populate dropdown/select/combobox dynamically?

  2. 2

    Parse .txt file to populate html select with jQuery

  3. 3

    How to HTML select in jQuery

  4. 4

    Dynamically add html select onClick of another select box option

  5. 5

    How to populate dependant select menus dynamically using jQuery, PHP and MySQL?

  6. 6

    php html form select option to populate text field jquery

  7. 7

    Select on Change will change another select html javascript or jquery

  8. 8

    Select on Change will change another select html javascript or jquery

  9. 9

    How to dynamically preset/select the value of a html select object using Django?

  10. 10

    jQuery variable (select in html)

  11. 11

    JQuery to populate select list based on another select list

  12. 12

    How to select the nth HTML row in jQuery

  13. 13

    How to set text a select html with jquery?

  14. 14

    How to select html tag of particular index in jquery

  15. 15

    How to select html elements using jQuery in Phantomjs?

  16. 16

    How to add and select an element in html using jquery

  17. 17

    populate a HTML select in form using Javascript

  18. 18

    Javascript looping through an object to populate an HTML select

  19. 19

    Javascript looping through an object to populate an HTML select

  20. 20

    How to select <select> elements with no html in them through JQuery

  21. 21

    Populate a dropdown by another select

  22. 22

    How do I dynamically query the DB based on HTML select option?

  23. 23

    How to populate a select box with the selected values of another select box

  24. 24

    How do i populate a select with a db call based on another select

  25. 25

    Populate select elements dynamically from json data file using jquery

  26. 26

    How do I populate an html text input field based on an html select option

  27. 27

    how to populate a select element using jquery?

  28. 28

    How to populate bootstrap multi select using jQuery

  29. 29

    Populate items into SELECT with Jquery

HotTag

Archive