Jeg har 2 funktioner i JavaScript, den ene fjerner objekter, den anden tilføjer.
Når der bliver fjernet et objekt, vil jeg have den til at minuse i <input type="text" name="pris"> med prisen fra det valgte object.
Når der derimod tilføjet, vil jeg have den til at plusse med prisen.
Kan det lade sig gøre og hvordan?
strSQL = "SELECT * FROM varer"
Set RS = Conn.Execute(strSQL)
If RS.EOF Then
Response.Write ""
Else
strRetter = "<script type=""text/javascript"">" & vbCrLf
strRetter = strRetter & "retter = ["
Do Until RS.EOF
intId = RS("id")
strNavn = RS("navn")
strPris = RS("pris")
strBillede = RS("billede")
strRetter = strRetter & "[""" & strNavn & """,""" & strPris & """,""" & strBillede & """]," & vbCrLf
RS.MoveNext
Loop
strRetter = strRetter & "];" & vbCrLf
strRetter = strRetter & "</script>" & vbCrLf
End If
Response.Write strRetter
%>
<script type="text/javascript">
<!-- Start
function SelectAll(fromObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
fromObject.options[i].text,fromObject.options[i].selected = true;
}
}
function removeItems() {
selselect1 = document.getElementById("select1");
while(selselect1.selectedIndex>=0)
selselect1.removeChild(selselect1.options[selselect1.selectedIndex]);
}
function insertItems() {
selselect2 = document.getElementById("select2");
if(selselect2.selectedIndex<0)
return;
selselect1 = document.getElementById("select1");
for(j=0; j<selselect2.options.length; j++) {
if(selselect2.options[j].selected) {
opt = document.createElement("OPTION");
opt.innerHTML = opt.value = selselect2.options[j].value;
selselect1.appendChild(opt);
}
}
selselect2.selectedIndex=-1;
}
function init() {
selselect2 = document.getElementById("select2");
for(j=0; j<retter.length; j++) {
opt = document.createElement("OPTION");
opt.value = retter[j][0];
opt.innerHTML = retter[j][0];
selselect2.appendChild(opt);
}
}
function showPrice() {
index = document.getElementById("select2").selectedIndex;
divPRIS = document.getElementById("PRIS");
divPRIS.innerHTML = "<br><img src=gfx/varerbilleder/"+retter[index][3]+" align=right><b>"+retter[index][0]+"</b><br><b>Pris:</b> "+retter[index][1]+" kr.";
}
// Slut -->
</script>
<form method="post" action="?mode=1">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>
<p align="left">Menukort:<br>
<body onload="init()">
<select multiple name="select2" onchange="showPrice()" size='8' style="width:235; height:118" class="input"></select>
</td>
<td width="70">
<center>
<input type='button' value='Tilføj »' onClick="insertItems(this.form.select2,this.form.select1)" class="button">
<br><br>
<input type='button' value='« Fjern' onClick="removeItems(this.form.select1,this.form.select2)" class="button">
</center>
</td>
<td>
<p align="right">Bestilling:<br>
<select multiple name="select1" size='8' style="width:235; height:118" class="input"></select><br></p>
</td>
</tr>
</table>
<center>
<input type="button" value="Videre" onClick="SelectAll(this.form.select1);submit()" class="button">
</center>
<div id="PRIS"></div>
</form>
Indlæg senest redigeret d. 28.03.2006 13:12 af Bruger #8392