"Christmas - the time to fix the computers of your loved ones" « Lord Wyrm

Java-Script problem:(

Triplexhfd 27.06.2004 - 10:43 414 1 Thread rating
Posts

Triplexhfd

Bloody Newbie
Registered: Jun 2004
Location: Althofen
Posts: 0
Huhu leute, ich weiiß nich ob mir jmd. helfen kann, aber hab da ein problem mit ner aufgabe....

das ist mein taschenrechner... aber es fehlen absicherungen wenn man zB 2 punkte eingibt oder 2 mal + oder -... kann mir da einer helfen? mfg
<html>
<head>
<title>Taschenrechner@Projektentwicklung</title>
<script language="JavaScript">
<!--
function addChar(input, character)
{
if(input.value == null || input.value == "0")
input.value = character
else
input.value += character
}

function deleteChar(input)
{
input.value = input.value.substring(0, input.value.length - 1)
}

function changeSign(input)
{
// could use input.value = 0 - input.value, but let's show off substring
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length)
else
input.value = "-" + input.value
}

function compute(form)
{
form.display.value = eval(form.display.value)
}

function square(form)
{
form.display.value = eval(form.display.value) * eval(form.display.value)
}

function checkNum(str)
{
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i+1)
if (ch < "0" || ch > "9") {
if (ch != "/" && ch != "*" && ch != "+" && ch != "-"
&& ch != "(" && ch!= ")") {
alert("Falsche Eingabe!")
return false
}
}
}
return true
}

//-->
</script>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<!--tr => neue tabelllenzeile
td => neue Datenzelle
//-->
<body>
<center>
<form>
<table border="5" align=center>
<tr align="center" bgcolor=red> <!-- Erste Zeile - Eingabefeld //-->
<td colspan = 4>
<table border="3" bgcolor=red>
<tr>
<td align=center><input name="display" value="0" size=20 readonly></td> <!--Eingabefeld, größe vom feld //-->
</tr>
</table>
</td>
</tr>
<tr align=center bgcolor=red> <!-- Zweite Zeile - 7,8,9 und Divisionszeichen //-->
<td><input type="button" value=" 7 " onClick="addChar(this.form.display, '7')"></td>
<td><input type="button" value=" 8 " onClick="addChar(this.form.display, '8')"></td>
<td><input type="button" value=" 9 " onClick="addChar(this.form.display, '9')"></td>
<td><input type="button" value=" / " onClick="addChar(this.form.display, '/')"></td>
</tr>
<tr align=center bgcolor=red> <!-- Dritte Zeile - 4,5,6,* //-->
<td><input type="button" value=" 4 " onClick="addChar(this.form.display, '4')"></td>
<td><input type="button" value=" 5 " onClick="addChar(this.form.display, '5')"></td>
<td><input type="button" value=" 6 " onClick="addChar(this.form.display, '6')"></td>
<td><input type="button" value=" * " onClick="addChar(this.form.display, '*')"></td>
</tr>
<tr align=center bgcolor=white> <!-- Vierte Zeile - 1,2,3,- //-->
<td><input type="button" value=" 1 " onClick="addChar(this.form.display, '1')"></td>
<td><input type="button" value=" 2 " onClick="addChar(this.form.display, '2')"></td>
<td><input type="button" value=" 3 " onClick="addChar(this.form.display, '3')"></td>
<td><input type="button" value=" - " onClick="addChar(this.form.display, '-')"></td>
</tr>
<tr align=center bgcolor=white> <!-- Fünfte Zeile - 0,.,+/-,+ //-->
<td><input type="button" value=" 0 " onClick="addChar(this.form.display, '0')"></td>
<td><input type="button" value=" . " onClick="addChar(this.form.display, '.')"></td>
<td><input type="button" value=" +/- " onClick="changeSign(this.form.display)"></td>
<td><input type="button" value=" + " onClick="addChar(this.form.display, '+')"></td>
</tr>
<tr align=center bgcolor=red> <!-- Sechste Zeile - (,),sqrt,<- //-->
<td><input type="button" value=" ( " onClick="addChar(this.form.display, '(')"></td>
<td><input type="button" value=" ) " onClick="addChar(this.form.display, ')')"></td>
<td><input type="button" value=" sqrt " onClick="if (checkNum(this.form.display.value)){ square(this.form) }"></td>
<td><input type="button" value=" <- " onClick="deleteChar(this.form.display)"></td>
</tr>
<tr align=center bgcolor=red>
<td colspan="2"><input type="button" value=" Enter " name="enter" onClick="if (checkNum(this.form.display.value)){ compute(this.form)}"></td>
<td colspan="2"><input type="button" value=" C " onClick="this.form.display.value = 0 "></td>
</tr>
<tr align=center bgcolor=red>
<td colspan="2"><u><i><b><font color="BLACK">Copyright by</font></b></i></u></td>
<td colspan="2"><u><i><b><font color="BLACK">Triplex@HFD</font></b></i></u></td>
</table>
</form>
</center>
</body>
</html>

fleshmark

GameDev
Avatar
Registered: Aug 2000
Location: Wien
Posts: 2958
probiers mal dort zu posten

http://www.overclockers.at/forumdis...&forumid=40

bin leider kein JS mensch ;)
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz