ユーザーが滞在したい場所をいくつか選択できるフォームがあり、各場所に行く時間を指定する必要がありますが、最初に、すべての場所に行く予定の一般的な日数を入力する必要がありますたとえば、最初の場所で2日、2番目の場所で3日、2つの場所に滞在したい場合は、最初に5日を入力してから、滞在したい場所を選択して、場所ごとに何日か指定する必要があります。そこにいたい。ユーザーが場所に間違った日数を入力するのを防ぐために、場所ごとに選択要素を作成したので、ユーザーが一般的な日数を入力すると、選択要素にその情報(1からのオプション)を入力します。日数まで)、それはうまく機能しています、
function fillUpSelects2(start, top, who) {
var optionArray = new Array();
// create the new options
for (var i = 1; i <= top; i++) {
optionArray.push(new Option(i, i));
}
// get all the select elements
var selects = jQuery("select.estanciaselect");
// loop through the selects to change their content
for (var i = 0; i < selects.length; i++) {
// if selects[i] is not the one who triggered the change event
if (selects[i].getAttribute('id') != who) {
// then I erase all its options
selects[i].options.length = 0;
//and here is where it is supposed to add the new options
for (var j = 0; j < optionArray.length; j++) {
selects[i].options[selects[i].options.length] = optionArray[j];
}
}
}
}
これを実行すると、すべての選択が空になりますが、最後の選択は適切に埋められます