As mentioned in the comment - the option
element itself does not trigger or receive events - they are passed up to the parent element so it is on the select
tag that you would assign an event listener.
If you pass an event
and a value to the event handler you can quite easily set the desired colour on the particular cell by referring up the tree to the parent and down to the particular cell ( ie: parentNode.parentNode as see below )
<table>
<tr>
<th>aircrift type</th>
<th>registration</th>
<th>arrival time</th>
<th>departure time</th>
<th>actions</th>
</tr>
<tr>
<td>Boeing 747</td>
<td>BA747-01KDS</td>
<td>18:30</td>
<td>16:30</td>
<td>
<select name='aircraft-state' onchange='setcolour(event,this.value)'>
<option selected>Please Select
<option value='airborne'>Airborne
<option value='landed'>Landed
<option value='boarding'>Boarding
<option value='fuelling'>Fuelling
<option value='changeover'>Changeover
</select>
</td>
</tr>
<tr>
<td>Airbus A380</td>
<td>KLM380-FD76</td>
<td>19:45</td>
<td>15:00</td>
<td>
<select name='aircraft-state' onchange='setcolour(event,this.value)'>
<option selected>Please Select
<option value='airborne'>Airborne
<option value='landed'>Landed
<option value='boarding'>Boarding
<option value='fuelling'>Fuelling
<option value='changeover'>Changeover
</select>
</td>
</tr>
<tr>
<td>A10 Warthog</td>
<td>WB-USAF-0034</td>
<td>20:00</td>
<td>19:20</td>
<td>
<select name='aircraft-state' onchange='setcolour(event,this.value)'>
<option selected>Please Select
<option value='airborne'>Airborne
<option value='landed'>Landed
<option value='boarding'>Boarding
<option value='fuelling'>Fuelling
<option value='changeover'>Changeover
</select>
</td>
</tr>
</table>
<script>
function setcolour(e,v){
e.preventDefault();
var tr = e.target.parentNode.parentNode;
switch( v ){
case 'airborne':
tr.childNodes[3].style.backgroundColor='green';
break;
case 'landed':
tr.childNodes[3].style.backgroundColor='gray';
break;
case 'boarding':
tr.childNodes[3].style.backgroundColor='red';
break;
case 'fuelling':
tr.childNodes[3].style.backgroundColor='yellow';
break;
case 'changeover':
tr.childNodes[3].style.backgroundColor='purple';
break;
}
}
</script>
The modification I mentioned should you wish to set the entire row colour according to the selected value you would change the relevant lines above to:
tr.style.backgroundColor='<COLOUR>';