我正在從select元素中的onChange()函數調用的簡單switch語句來設置文本字段的值。目前它沒有設置值。任何有關改進代碼的見解將不勝感激。JavaScript:switch語句沒有在文本框中設置值
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>
謝謝!
失去'形式[0] .'在'document.forms [0] .getElementById' – Igor 2014-08-28 20:11:16