Hilfestellung zu Script
David Hörpel
- javascript
0 Cheatah0 Jürgen Berkemeier0 Gregor
Hallo!
Ich habe ein ganz einfach gestricktes Script für eine Auswertung (richtig/falsch) programmiert. Im folgenden Code, wird das Script trotz for-Schleife nach dem ersten if-Block unterbrochen:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="1" height="200"> </td>
<td width="100%" valign="top">
<script language="JavaScript" type="text/javascript">
var a = "schröder";
b = "anwendungssoftware";
c = "bild";
document.open();
function Ergebnis()
{
for (i=0; i<=2; i++) {
if (document.form1.form1[0].checked == true)
document.writeln("Ihre Antwort " +a+ " ist richtig!")
else if (document.form1.form1[1].checked == true)
document.writeln("Ihre Antwort " +document.form1.form1[1].value+ " ist leider falsch!")
else (document.form1.form1[2].checked == true)
document.writeln("Ihre Antwort " +document.form1.form1[2].value+ " ist leider falsch!")
if (document.form2.form2[0].checked == true)
document.writeln("Ihre Antwort " +b+ " ist richtig!")
else if (document.form2.form2[1].checked == true)
document.writeln("Ihre Antwort " +document.form2.form2[1].value+ " ist leider falsch!")
else (document.form2.form2[2].checked == true)
document.writeln("Ihre Antwort " +document.form2.form2[2].value+ " ist leider falsch!")
if (document.form3.form3[0].checked == true)
document.writeln("Ihre Antwort " +c+ " ist richtig!")
else if (document.form3.form3[1].checked == true)
document.writeln("Ihre Antwort " +document.form2.form2[1].value+ " ist leider falsch!")
else (document.form3.form3[2].checked == true)
document.writeln("Ihre Antwort " +document.form3.form3[2].value+ " ist leider falsch!")
}
}
document.close();
document.open();
document.writeln("<p>Wie heisst der Bundeskanzler?</p><form name='form1' method='post' action=''><p> <input type='radio' name='form1' value='schröder'>Schröder</p><p> <input type='radio' name='form1' value='kohl'>Kohl </p><p><input type='radio' name='form1' value='schmidt'>Schmidt </p></form><p>Was für Software stellt SAP her?</p><form name='form2' method='post' action=''><p> <input type='radio' name='form2' value='anwendungssoftware'>Anwendungssoftware</p><p><input type='radio' name='form2' value='entwicklersoftware'>Entwicklersoftware</p><p><input type='radio' name='form2' value='privatanwender'>Software für den Privatanwender</p></form><p>Welche Zeitung wird in Deutschland am Meisten gelesen?</p><form name='form3' method='post' action=''><p><input type='radio' name='form3' value='bild'>Bild</p><p><input type='radio' name='form3' value='süddeutsche'>Süddeutsche</p>")
document.writeln("<p><input type='radio' name='form3' value='faz'>FAZ </p><br><input type='button' name='button' onClick='Ergebnis()' value='Abschicken'></form>");
document.close();
</script>
<p> </p>
</td>
</tr>
</table>
</body>
</html>
Kann mir einer sagen, wieso? Danke!
Gruß David!
Hi,
Im folgenden Code, wird das Script trotz for-Schleife nach dem ersten if-Block unterbrochen:
Dir ist aber schon bewusst, dass ein document.write() in ein fertig gerendertes Dokument dieses vernichtet, so dass das Formular nicht mehr existiert?
Cheatah
Hallo David,
in der For-Schleife kommt der Laufindex "i" nicht vor. Die Schleife macht also 3-mal das Gleiche.
Du solltest Dir angewöhnen, sorgfältiger einzurücken, man blickt ja kaum durch.
Gruß, Jürgen
Hallo David
28 document.writeln("Ihre Antwort " [...]
29 else IF_VERGESSEN? (document.form1.form1[2]. [...]
30 document.writeln("Ihre Antwort " +documen [...]
Grüße
Gregor