I have a drop down menu that will run a function onchange. The function takes times from an array , adds a specific amount of time , then changes the innerHTML of the table.
The code works , but is there a simpler version? I plan on adding more options to the drop down menu.
HTML
<select id="sel1" onchange="myFunction()">
<option value="VIC">VIC</option>
<option value="NSW">NSW</option>
</select>
<table id="myTable" border="1">
<tbody>
<tr>
<td>A</td>
<td>2016-08-24 16:00</td>
<td>C</td>
</tr>
<tr>
<td>A</td>
<td>2016-08-24 16:00</td>
<td>C</td>
</tr>
</tbody>
Javascript
function myFunction(){
var cellData = ["2016-08-24 15:45", "2016-08-24 16:00"];
var myTable = document.getElementById("myTable");
if (document.getElementById("sel1").value == "VIC") {
var vicTime = [];
for (i=0; i<cellData.length; i++) {
date = moment(cellData[i]).add(1, 'h').format('MM/DD/YYYY hh:mm a');
vicTime.push(date);
myTable.rows[i].cells[1].innerHTML = vicTime[i];
}}
if (document.getElementById("sel1").value == "NSW") {
var nswTime = [];
var j;
for (j=0; j<cellData.length; j++) {
date = moment(cellData[j]).add(5, 'h').format('MM/DD/YYYY hh:mm a');
nswTime.push(date);
myTable.rows[j].cells[1].innerHTML = nswTime[j];
}}};