0

This is the JavaScript. The select has an id of 'counties'.

The table is to be inserted into a div called 'up_bottom'.

var leagueArray = [];
function addTeams() {
  var county=document.getElementById("counties");
  var val = county.options[county.selectedIndex].value;
  leagueArray.push(val);
  function display() {
    var table = document.createElement("table");
    for (var i=0; i<leagueArray.length; i++) {
      var row = table.insertRow();
      for (var j=0; j<leagueArray[i].length; j++) {
        var cell = row.insertCell();
        cell.appendChild(document.createTextNode(leagueArray[i]));
      }
    }
    var tableDiv = document.getElementById("up_bottom");
    tableDiv.appendChild(table);
  }
  display();
}
shA.t
  • 16,580
  • 5
  • 54
  • 111
nedduff
  • 97
  • 1
  • 9

2 Answers2

0

Try this,

function addTeams(){
    var leagueArray = [];
    var county=document.getElementById("counties");
    for (i = 0; i < county.options.length; i++) {
       leagueArray[i] = county.options[i].value;
    }
    display(leagueArray);
}

function display(leagueArray) {
    var table = document.createElement("table");
    for (var i=0; i<leagueArray.length; i++) {
        var row = table.insertRow();
        for (var j=0; j<leagueArray[i].length; j++) {
            var cell = row.insertCell();
            cell.appendChild(document.createTextNode(leagueArray[i]));
        }
    }
    var tableDiv = document.getElementById("up_bottom");
    tableDiv.appendChild(table);
}

addTeams();
0

Please do the following Steps

  1. Get Selected Value from Dropdown
  2. Put the Selected Value into Array
  3. Create A String of tr element and append it to Table before First tr element