私はカテゴリとjavascriptにアイテムを割り当てることができるページを持っています。これにより、ユーザーは1つのボックスから複数のアイテムを左右に1つずつ移動できます。選択肢を微調整します(右のボックスで終わります)。リストボックスの代わりにリスト間を移動できる方が良いかもしれませんが、選択ボックスは、クリックして選択すると良いでしょう。ユーザーが完了したら、私は右のボックスにPHPスクリプトに項目を投稿する必要があります。しかし、正しいリスト内のすべてのアイテムをキャプチャする方法を理解するのに問題があります。スクリプトにはフォームがないので、document.formから取得できません。アイテムは実際には選択されていないので、リストに値を設定するだけで、それらをすべて取得したいのです。リスト全体を持つ変数はありますか?スクリプトは時間がかかるのでここでは機能する関数です。基本的には、最後に右のボックスに要素のリストを書き出す方法が必要です。ご意見ありがとうございます。javascript phpのすべてのリストボックスの値を取得する
function moveToRightOrLeft(side) {
var listLeft = document.getElementById('selectLeft');
var listRight = document.getElementById('selectRight');
if (side == 1) {
if (listLeft.options.length == 0) {
alert('You have already assigned all items to the category');
return false;
} else {
var selectedItem = listLeft.options.selectedIndex;
move(listRight, listLeft.options[selectedItem].value, listLeft.options[selectedItem].text);
listLeft.remove(selectedItem);
if (listLeft.options.length > 0) {
listLeft.options[0].selected = true;
}
}
} else if (side == 2) {
if (listRight.options.length == 0) {
alert('The list is empty');
return false;
} else {
var selectedItem = listRight.options.selectedIndex;
move(listLeft, listRight.options[selectedItem].value, listRight.options[selectedItem].text);
listRight.remove(selectedItem);
if (listRight.options.length > 0) {
listRight.options[0].selected = true;
}
}
}
}
function move(listBoxTo, optionValue, optionDisplayText) {
var newOption = document.createElement("option");
newOption.value = optionValue;
newOption.text = optionDisplayText;
listBoxTo.add(newOption, null);
return true;
}
-1。 –
@DenisErmolin –