Jeg har 2 løsninger:
Den første bruger multiple select som dit udkast
<html><head><style>
select {
width:200px;
}
</style><script type="text/javascript">
// Liste med retternes navne efterfulgt af prisen
retter = [
["Indisk curry",10],
["Pasta med pesto",12.5],
["Humus",15],
["Pasta med ketchup",17.5],
["Lasagne",20],
["Big mac",22.5],
["Whopper med cheese",25],
["Pizza",27.5],
["Shawarma",30]
];
function init() {
selMENU = document.getElementById("MENU");
for(j=0; j<retter.length; j++) {
opt = document.createElement("OPTION");
opt.innerHTML = opt.value = retter[j][0];
selMENU.appendChild(opt);
}
}
function insertItems() {
selMENU = document.getElementById("MENU");
if(selMENU.selectedIndex<0)
return;
selBESTILLING = document.getElementById("BESTILLING");
for(j=0; j<selMENU.options.length; j++) {
if(selMENU.options[j].selected) {
opt = document.createElement("OPTION");
opt.innerHTML = opt.value = selMENU.options[j].value;
selBESTILLING.appendChild(opt);
}
}
selMENU.selectedIndex=-1;
}
function removeItems() {
selBESTILLING = document.getElementById("BESTILLING");
while(selBESTILLING.selectedIndex>=0)
selBESTILLING.removeChild(selBESTILLING.options[selBESTILLING.selectedIndex]);
}
function showPrice() {
index = document.getElementById("MENU").selectedIndex;
divPRIS = document.getElementById("PRIS");
divPRIS.innerHTML = retter[index][0]+" "+retter[index][1]+"kr.";
}
</script></head><body onload="init()">
<select size=8 id="MENU" multiple onchange="showPrice()"></select>
<button onclick="insertItems()">Add</button><button onclick="removeItems()">Remove</button>
<select size=8 id="BESTILLING" multiple></select>
<div id="PRIS"></div>
</body></html>
Den anden bruger single select uden slet/tilføj knapper
<html><head><style>
select {
width:200px;
}
</style><script type="text/javascript">
// Liste med retternes navne efterfulgt af prisen
retter = [
["Indisk curry",10],
["Pasta med pesto",12.5],
["Humus",15],
["Pasta med ketchup",17.5],
["Lasagne",20],
["Big mac",22.5],
["Whopper med cheese",25],
["Pizza",27.5],
["Shawarma",30]
];
function init() {
sel = document.getElementById("MENU");
for(j=0; j<retter.length; j++) {
opt = document.createElement("OPTION");
opt.innerHTML = opt.value = retter[j][0];
sel.appendChild(opt);
}
}
function insertSelectedItem(obj) {
sel = document.getElementById("BESTILLING");
opt = document.createElement("OPTION");
opt.innerHTML = opt.value = obj.value;
showPrice();
sel.appendChild(opt);
obj.selectedIndex=-1;
}
function deleteSelectedItem(obj) {
obj.removeChild(obj.options[obj.selectedIndex]);
}
function showPrice() {
index = document.getElementById("MENU").selectedIndex;
divPRIS = document.getElementById("PRIS");
divPRIS.innerHTML = retter[index][0]+" "+retter[index][1]+"kr.";
}
</script></head><body onload="init()">
<select size=8 onchange="insertSelectedItem(this)" id="MENU"></select>
<select size=8 onchange="deleteSelectedItem(this)" id="BESTILLING"></select>
<div id="PRIS"></div>
</body></html>
[Redigeret d. 10/02-06 18:01:44 af Brian]