Set the value and text of a select option from Javascript table

Goraby

I have a table variable

var stations = [
    [0,'JAMAA EL FNA','L1'],
    [1,'KOUTOUBIA','L1'],
    [2,'HOTEL DE VILLE','L1'],
...

How to set the values and text of a dropdown box from this table (second column)?

 <select id="select1" name="select1">
    <option value='test'>test<option>
 </select>
Ullas Hunka

You can use the code as follows;

var stations = [
    [0,'JAMAA EL FNA','L1'],
    [1,'KOUTOUBIA','L1'],
    [2,'HOTEL DE VILLE','L1']];
    
    for(var i=0;i<stations.length;i++){
    var opText = "<option val='"+stations[i][0]+"'>"+stations[i][1]+"</option>";
      $("#selecObject").append(opText);
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="selecObject"></select>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set value of Select option in Javascript

From Dev

Use JQuery to set the select option value and text from Array

From Dev

Use JQuery to set the select option value and text from Array

From Dev

Retrieve text (not value) from select option tag

From Dev

how to select the option value in dynamic html table javascript. not getting updated option value from the database in the jsp page

From Dev

set a radio button value based on option select using Javascript only

From Dev

set html option value with optgroup in select field using JavaScript

From Dev

3 option select set value from database remove onchange

From Dev

How I get the text instead value from a select option in CodeIgniter

From Dev

use jQuery to select option from menu based on its text not value

From Dev

Angular select box with value differ from option text

From Java

Set select option 'selected', by value

From Dev

How to set the value of select option

From Dev

How to set the value of select option

From Dev

Find select option value by text

From Dev

JavaScript/jQuery - Get option attribute from select menu by text

From Dev

jquery click select option value with option text

From Dev

javascript change select option text

From Dev

How to get value of Select option from loop in JavaScript

From Dev

Getting Select Option Value with Javascript

From Dev

fill an option text/value with JavaScript

From Dev

Set <select> value in Javascript

From Dev

Option value from select statement

From Dev

Remove option value from the select option

From Dev

How to set the value and text values of a select element from a list of integers

From Dev

How to add row in table with Javascript , table value checkbox,textbox,radio,select option?

From Dev

HTML/PHP set value of option in select where I filled select from array

From Dev

Select and display value from each new "select option" created for table row

From Dev

Dynamically set the VALUE of an text-INPUT element to default by clicking SELECT option

Related Related

  1. 1

    Set value of Select option in Javascript

  2. 2

    Use JQuery to set the select option value and text from Array

  3. 3

    Use JQuery to set the select option value and text from Array

  4. 4

    Retrieve text (not value) from select option tag

  5. 5

    how to select the option value in dynamic html table javascript. not getting updated option value from the database in the jsp page

  6. 6

    set a radio button value based on option select using Javascript only

  7. 7

    set html option value with optgroup in select field using JavaScript

  8. 8

    3 option select set value from database remove onchange

  9. 9

    How I get the text instead value from a select option in CodeIgniter

  10. 10

    use jQuery to select option from menu based on its text not value

  11. 11

    Angular select box with value differ from option text

  12. 12

    Set select option 'selected', by value

  13. 13

    How to set the value of select option

  14. 14

    How to set the value of select option

  15. 15

    Find select option value by text

  16. 16

    JavaScript/jQuery - Get option attribute from select menu by text

  17. 17

    jquery click select option value with option text

  18. 18

    javascript change select option text

  19. 19

    How to get value of Select option from loop in JavaScript

  20. 20

    Getting Select Option Value with Javascript

  21. 21

    fill an option text/value with JavaScript

  22. 22

    Set <select> value in Javascript

  23. 23

    Option value from select statement

  24. 24

    Remove option value from the select option

  25. 25

    How to set the value and text values of a select element from a list of integers

  26. 26

    How to add row in table with Javascript , table value checkbox,textbox,radio,select option?

  27. 27

    HTML/PHP set value of option in select where I filled select from array

  28. 28

    Select and display value from each new "select option" created for table row

  29. 29

    Dynamically set the VALUE of an text-INPUT element to default by clicking SELECT option

HotTag

Archive