Mein nicht besonders ergeiziges Ziel, einen Taschenrechner zu basteln, der sin,cos und tan-Werte berechnet (hatten wir gerade in Mathe) scheiterte bereits an der Tatsache, dass das Ergebnis nicht mit dem des Taschenrechners übereinstimmt. Leider habe ich nicht die Spur einer Ahnung, warum.
HELP!!
Hier der Quelltext der ganzen Datei:
<html>
<head>
<title>JS-Calc</title>
<script language="JavaScript">
<!--
function umrechnen()
{
eingabe = document.rechner.display.value
if (document.rechner.u_art[0].checked == true)
{ document.rechner.display.value = Math.sin(eingabe); }
else if (document.rechner.u_art[1].checked == true)
{ document.rechner.display.value = Math.cos(eingabe); }
else if (document.rechner.u_art[2].checked == true)
{ document.rechner.display.value = Math.tan(eingabe); }
if (document.rechner.display.value == "NaN")
{ document.rechner.display.value = "Keine Zahl!" }
}
function backspace()
{
x = document.rechner.display.value;
y = document.rechner.display.value.length;
y = y-1
document.rechner.display.value = x.substr(0,y);
}
//-->
</script>
<style>
body { margin:0 }
th,td { font-family:Arial;font-size:12 }
</style>
</head>
<body bgcolor=gold text=black link=darkred alink=gold vlink=darkred>
<nobr>
<form name="rechner">
<table border=1 cellpadding=0 cellspacing=0>
<tr>
<th><input type="button" value=" 1 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '1';"></th>
<th><input type="button" value=" 2 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '2';"></th>
<th><input type="button" value=" 3 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '3';"></th>
<td align=center><input name="display" size=13 readonly></td>
</tr>
<tr>
<th><input type="button" value=" 4 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '4';"></th>
<th><input type="button" value=" 5 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '5';"></th>
<th><input type="button" value=" 6 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '6';"></th>
<td><input type=radio value="sin" name="u_art" checked>SIN
<input type=radio value="cos" name="u_art">COS
<input type=radio value="tan" name="u_art">TAN</td>
</tr>
<tr>
<th><input type="button" value=" 7 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '7';"></th>
<th><input type="button" value=" 8 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '8';"></th>
<th><input type="button" value=" 9 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '9';"></th>
<td><B><input type="button" value=" 0 " onClick="JavaScript:document.rechner.display.value = document.rechner.display.value + '0';">
<input type="button" value="<--" onClick="JavaScript:backspace();">
<input name="enter" type="button" value="Enter" onClick="umrechnen();">
<input name="neu" type="reset" value="neu"></B></td>
</tr>
</form>
</table>
</body>
</html>
Ich glaube nicht, dass hier ein ganz banaler Fehler vorliegt, denn solche Dingers entdecke ich normalerweise (spätestens nach stundenlangem Suchen). =:-]
Gibt es eigentlich eine Möglichkeit zu fragen, welches Element eines Radio-Buttons gewählt ist, mit der man also nicht jedes einzelne Element überprüfen muss (also sowas wie document.rechner.u_art.checked.value)?
Also, heute ist der 15.2.99. Ich hoffe, dass Forum wird ganz schnell wieder geöffnet...