これについて一生懸命考えすぎているだけなのか、それとも何なのかわかりません。通話の結果に基づいて特定のオプションを選択できるようにしたいだけです。現在、呼び出しは郵便番号に基づいて都市、州、国を生成します。GET からの応答は "Sacramento | CA | United States" です。応答を入力ボックスに入力するのは簡単ですが、応答に基づいてオプションを選択する方法がわかりません。これは可能ですか?メソッドのプロパティをいくつか調べてみましたが、実際に使用できるものは何もありません。
これが Get スクリプトです。
<script type="text/javascript">
var req;
var oldData;
var doesNotSupport = true;
function getAddress(url, number)
{
if (number == "" || oldData == number || !doesNotSupport)
return;
oldData = number;
document.getElementById('city').value = "Searching ...";
document.getElementById('state').value = "Searching ...";
document.getElementById('country').value = "Searching ...";
if (window.XMLHttpRequest) {
req = new XMLHttpRequest;
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url + '?number=' + number + '&zip=' + number, true);
req.send(null);
} else {
alert("Your browser does not support XMLHttpRequest technology!");
doesNotSupport = false;
}
}
</script>
これが応答スクリプトです
<script type="text/javascript">
function processReqChange() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var Result = req.responseText.split("|");
document.getElementById('city').value = Result[0];
document.getElementById('state').value = Result[1];
This is the problem child.
document.getElementById('country').value = Result[2];
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
</script>
オプション設定
<option name="(abbr.)" value="(full name)">Full Name</option>
すなわち
<option name="CA" value="California">California</option>
.value プロパティを置き換えるものを探しています。みたいなものdocument.getElementById('state').childNode.attribute.name = Result[1]
とか。
完全なページ ファイルへのリンクは次のとおりですhttp://ge.tt/99dJ1J9?c