function SetUtcTimeZone() {
var UTCTimeZone = document.getElementById("txtPortorAnchorDeparture").value;
document.getElementById('ddlUTCTimeZone').selectedIndex = UTCTimeZone;
}
如何使用下拉列表ID
将文本框值设置为下拉列表答案 0 :(得分:1)
我猜它会是这样的:
function SetTxt() {
var indx = document.getElementById('ddlUTCTimeZone').selectedIndex;
var val = document.getElementById('ddlUTCTimeZone').options[indx].text;
document.getElementById("txtPortorAnchorDeparture").value = val;
}
答案 1 :(得分:1)
只需将.selectedIndex
替换为.value
即可
试试这个
function SetUtcTimeZone() {
var UTCTimeZone = document.getElementById("txtPortorAnchorDeparture").value;
document.getElementById('ddlUTCTimeZone').value = UTCTimeZone;
}

<!-- Simple example -->
<select id="ddlUTCTimeZone">
<option value="1">USA</option>
<option value="2">Egypt</option>
<option value="0">GMT</option>
</select>
<input id="txtPortorAnchorDeparture" type="text" />
<button type="button" onclick="SetUtcTimeZone()">Go</button>
&#13;
答案 2 :(得分:0)
这是一个简单的功能
function dropdownToTextbox(dropdown, textbox) {
var selectedOption = dropdown.options[dropdown.selectedIndex];
textbox.value = selectedOption.value;
}