Checkboxabfrage in For - In Schleife

Hallo Leute,

bitte nicht für dumme Fragen schlagen, ich bin ein JavaScript Neuling.

Ich will eine Auswahlliste mit einigen Optionen (aus Checkboxen) bauen.

Das hat soweit geklappt aber ich will noche eine Preiskalkulation machen.

Dazu habe ich ein Array mit den Optionen und den Preisen erstellt und will mit einer For - In Schleife die Checkboxen abfragen und den Preis in die Kalkulation einbeziehen.

mein Array:
Code:
var optionen = new Array(
"m_absaugung",
"m_spuelpistole",
"m_wzbruchkontrolle",
"m_wzbruchkontrolle");
 
var preise = new Array();
m_absaugungpreis = 11000;
m_spuelpistolepreis = 12000;
m_wzbruchkontrollepreis = 13000;
m_kupplungseinheitpreis = 14000;

und die Abfrage dazu:
Code:
var gesamtpreis = m_standardpreis;
function addieren(){
var optionspreis;
for(i in optionen){
if (document.forms[optionen[i]].checked==checked)
{ optionspreis="test" }
else{ optionspreis="fehler" }}

Testweise habe ich mir nur den Wert "test" bzw. "fehler" ausgeben lassen aber ich bekomme immer nur "fehler" ausgegeben.

Ich bin mir sicher, dass das Problem in --
Code:
if (document.forms[optionen[i]].checked==checked)
-- liegt.

Meine Formularelemente sind alle in einem <form name="formular"> zusammengefasst wodurch ich eigendlich auf den Namen des einzelnen Formularelements zugreifen müsste. Aber genau das will mir nicht gelingen.

Kann mir dazu irgendjemend einen Tipp oder einen Link geben
 
Auf den ersten Blick sollte es:
Code:
if (document.formular.elements[optionen[i]].checked)
...tun, wenn nicht ,poste mal bitte das dazugehörige Formular.
 
Code:
<html><head><title>Baugruppenauswahl Superflex SF320</title>
<script language="Javascript">
 
function fktcheck()
{if (document.formular.e_messtaster.checked==false)
{if (document.formular.e_artis.checked==false)
{if (document.formular.e_wattpilote.checked==false)
{document.formular.e_steuerung[0].checked=true;
document.formular.e_steuerung[1].disabled=false;
document.formular.e_steuerung[0].disabled=false;
fkte_steuerung20()}}}}
 
var optionen = new Array(
"m_absaugung",
"m_spuelpistole",
"m_wzbruchkontrolle",
"m_wzbruchkontrolle");
 
var preise = new Array();
m_absaugungpreis = 11000;
m_spuelpistolepreis = 12000;
m_wzbruchkontrollepreis = 13000;
m_kupplungseinheitpreis = 14000;
 
var m_standardpreis = 100000; <!--Grundmaschinenpreis-->
 
 
function preisfelder(){
document.getElementById("m_standardpreisfeld").firstChild.nodeValue = m_standardpreis;
document.getElementById("m_absaugungpreisfeld").firstChild.nodeValue = m_absaugungpreis;
document.getElementById("m_spuelpistolepreisfeld").firstChild.nodeValue = m_spuelpistolepreis;
document.getElementById("m_wzbruchkontrollepreisfeld").firstChild.nodeValue = m_wzbruchkontrollepreis;
document.getElementById("m_kupplungseinheitpreisfeld").firstChild.nodeValue = m_kupplungseinheitpreis;
}
 
var gesamtpreis = m_standardpreis;
function addieren(){
var optionspreis;
for(i in optionen){
if (document.formular.elements[optionen[i]].checked==true)
{ optionspreis="test" }
else{ optionspreis="fehler" }}
 
 
gesamtpreis = optionspreis
 
document.getElementById("gesamtpreisfeld").firstChild.nodeValue = gesamtpreis;
}
 
 
 
 
<!-- Funktionen aus Tablle 1-->
function fktm_absaugung()
{if (document.formular.m_absaugung.checked==true) 
{ document.formular.m_absaugungtext.value="7900.xxxx-00.080";
}else{ document.formular.m_absaugungtext.value=" ";} addieren()}
 
function fktm_spuelpistole()
{if (document.formular.m_spuelpistole.checked==true) 
{ document.formular.m_spuelpistoletext.value="7900.xxxx-00.080";
}else{ document.formular.m_spuelpistoletext.value=" ";} addieren()}
 
function fktm_wzbruchkontrolle()
{if (document.formular.m_wzbruchkontrolle.checked==true) 
{ document.formular.m_wzbruchkontrolletext.value="7900.xxxx-00.080";
document.formular.e_wzbruchkontrtext.value="7900.xxxx-00.080";
document.formular.e_wzbruchkontr.checked=true;
document.formular.e_wzbruchkontr.disabled=true;
}else{ document.formular.m_wzbruchkontrolletext.value=" ";
document.formular.e_wzbruchkontrtext.value=" ";
document.formular.e_wzbruchkontr.checked=false;
document.formular.e_wzbruchkontr.disabled=false;} }
 
function fktm_kupplungseinheit()
{if (document.formular.m_kupplungseinheit.checked==true) 
{ document.formular.m_kupplungseinheittext.value="7900.xxxx-00.080";
}else{ document.formular.m_kupplungseinheittext.value=" ";} }
 
.
.
.
 
</script>
</head>
<body> <!--background="SF320-6-graukl.jpg"-->
<center><font size="6">Baugruppenauswahl</font>
<center><font size="5">Superflex SF320</font>
<form name="formular"> 
<center>
<table border="1" cellpadding="2"> <!-- 1. Tabelle-->
<tr> <!-- T1-1.Zeile-->
<td> <b> &nbsp; Nr. &nbsp; </b> </td> <!-- Nr-->
<td> <b> &nbsp; Auswahl Mechanikbaugruppen &nbsp; </b> </td> <!-- Beschr-->
<td> <b> Opt./Var. </b> </td> <!-- opt-->
<td> <b> &nbsp; Artikelnummer </b> </td> <!-- ANr--> 
<td> <b> &nbsp; Bedingungen &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td> <!-- Bed--> 
<td> <b> Preis in € </b> </td> <!-- preis-->
</tr>
<tr> &nbsp; <!-- T1-2.Zeile-->
<td> &nbsp </td> <!-- Nr-->
<td> <a href="datein\standardS320.htm">Standardmaschine</a> </td> <!-- Beschr-->
<td> &nbsp; </td> <!-- opt-->
<td> 7900.0001-00.010 </td> <!-- ANr-->
<td> &nbsp; </td> <!-- Bed--> 
<td id="m_standardpreisfeld"> &nbsp; </td> <!-- preis-->
</tr> 
<tr> <!-- T1-3.Zeile-->
<td> &nbsp;M1 </td> <!-- Nr-->
<td> <a href="datein\m_absaugung.htm">Absaugung</a> </td> <!-- Beschr-->
<td> <input type="checkbox" name="m_absaugung" onclick="fktm_absaugung()"> </td> <!-- opt-->
<td> <input type="textbox" name="m_absaugungtext" readonly="1" > </td> <!-- ANr-->
<td> &nbsp; </td> <!-- Bed--> 
<td id="m_absaugungpreisfeld"> &nbsp; </td> <!-- preis--> 
</tr>
<tr> <!-- T1-4.Zeile-->
<td> &nbsp;M2 </td> <!-- Nr-->
<td> <a href="datein\m_spuelpistole.htm">Spülpistole</a> </td> <!-- Beschr-->
<td> <input type="checkbox" name="m_spuelpistole" onclick="fktm_spuelpistole()"> </td> <!-- opt-->
<td> <input type="textbox" name="m_spuelpistoletext" readonly="1" > </td> <!-- ANr-->
<td> &nbsp; </td> <!-- Bed--> 
<td id="m_spuelpistolepreisfeld"> &nbsp; </td> <!-- preis-->
</tr>
<tr> <!-- T1-5.Zeile-->
<td> &nbsp;M3 </td> <!-- Nr-->
<td> <a href="datein\m_wzbruchkontrolle.htm">Werzeugbruchkontrolle</a> </td> <!-- Beschr-->
<td> <input type="checkbox" name="m_wzbruchkontrolle" onclick="fktm_wzbruchkontrolle()"> </td> <!-- opt-->
<td> <input type="textbox" name="m_wzbruchkontrolletext" readonly="1" > </td> <!-- ANr-->
<td> nur mit E1 verfügbar </td> <!-- Bed--> 
<td id="m_wzbruchkontrollepreisfeld"> &nbsp; </td> <!-- preis-->
</tr>
<tr> <!-- T1-6.Zeile-->
<td> &nbsp;M4 </td> <!-- Nr-->
<td> <a href="datein\m_kupplungseinheit.htm">Kupplungseinheit</a> </td> <!-- Beschr-->
<td> <input type="checkbox" name="m_kupplungseinheit" onclick="fktm_kupplungseinheit()"> </td> <!-- opt-->
<td> <input type="textbox" name="m_kupplungseinheittext" readonly="1" > </td> <!-- ANr-->
<td> &nbsp; </td> <!-- Bed--> 
<td id="m_kupplungseinheitpreisfeld"> &nbsp; 
<tr>
 
.
.
.

Nach der Änderung vom ersten Tipp bekomme ich immernoch "fehler" als Ausgabe.
 
Das geht schon... der "Fehler" liegt in deiner "Fehlerausgabe".

Da der Wert in der Schleife immer aufs neue überschrieben wird, erscheint "test" nur, wenn die letzte der 4 Boxen gecheckt ist.
Lasse dir "optionspreis" mal innerhalb der Schleife per alert() ausgeben... dann siehst du es.
 
Zurück