I am working on a simple switch statement called from an onChange() function in a select element to set the value of a text field. Currently it is not setting the value. Any insights on improving the code would be appreciated.
function setAgencyPrefix()
{
var r = document.forms[0].getElementById('agency');
var requestor = r.options[r.selectedIndex].value;
var a = document.forms[0].getElementById('agency_abbrev');
switch (requestor) {
case 'City of Banks':
a.value = 'BANKS';
break;
case 'City of Beaverton':
a.value = 'BVT';
break;
case 'City of Tigard':
a.value = 'TIG';
break;
case 'City of Tualatin':
a.value = 'TUAL';
break;
default:
a.value = 'OTHER';
break;
}
}
<td>
<select onChange="setAgencyPrefix();" id="agency" name="requesting_entity">
<option value="City of Beaverton">Beaverton</option>
<option value="City of Banks">Banks</option>
<option value="City of Tigard">Tigard</option>
<option value="City of Tualatin">Tualatin</option>
</select>
</td>
Thanks!
forms[0].indocument.forms[0].getElementById