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>
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.
Comments