Joern: Text und Checkbox Wert in Tabelle ausgeben

Beitrag lesen

if( document.form.checkbox1.checked == true)
  {apfel += '' + document.form.checkbox1.value + "<br>"};

Wobei der Leerstring, vor dem Formularfeldwert unnötig ist.

{apfel += document.form.checkbox1.value + "<br>"};

Struppi.

Ich möchte mich bei euch für eure Unterstützung bedanken!
Besonders gut finde ich das nicht platt die Lösung gepostet wird, so muss man selbst seinen Hirnschmalz ins rotieren bringen.
Nur so, glaube ich wird man die Sprache letztendlich verstehen.

Mithilfe eurer Tipps, einem Buch (hab ich mir extra zugelegt) und einem guten Freund hab ich es nun hinbekommen.

Für alle die es interesiert, so sieht nun mein Script (noch etwas erweitert) aus:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test</title>

<script type="text/javascript">

function ausgeben(){

temp0 = parseInt(0)
if (document.form.checkbox1.checked)
 {temp0 = parseInt(document.form.checkbox1.value)}

temp0txt = ''
if (document.form.checkbox1.checked)
 {temp0txt = document.form.checkbox1.id + " " + temp0 }

temp1 = parseInt(0)
if (document.form.checkbox2.checked)
 {temp1 = parseInt(document.form.checkbox2.value)}

temp1txt = ''
if (document.form.checkbox2.checked)
 {temp1txt = document.form.checkbox2.id + " " + temp1 }

temp2 = parseInt(0)
if (document.form.checkbox3.checked)
 {temp2 = parseInt(document.form.checkbox3.value)}

temp2txt = ''
if (document.form.checkbox3.checked)
 {temp2txt = document.form.checkbox3.id + " " + temp2 }

tempall = temp0+temp1+temp2
document.getElementById('summe').innerHTML = tempall;

temptext = temp0txt + "<br>" + temp1txt + "<br>" + temp2txt
document.getElementById('htmltext').innerHTML = temptext

return
}

</script>

</head>

<body>
<form name="form">

<p>
<input type="checkbox" name="checkbox1" value="120" id="checkwert1"> Checkwert 120&#8364;<br>
</p>

<input type="checkbox" name="checkbox2" value="150" id="checkwert2"> Checkwert2 150&#8364;<br>
</p>

<input type="checkbox" name="checkbox3" value="180" id="checkwert3"> Checkwert3 180&#8364;<br>

<p>
<input type="button" value="click" onclick="ausgeben();">
</p>

</form>

<table width="250" border="1" cellspacing="0" cellpadding="5">
<tr>
<td valign="top" width="60">Artikel:</td>
<td id="htmltext"></td>
</tr>
<tr>
<td valign="top">Summe:</td>
<td id="summe"></td>
</tr>
</table>

</body>
</html>