Написал я калькулятор, вроде бы все впорядке, но гугл ругается на сточку текста в js:
document.calculatorForm.display.value = current;
Ругается так: "Uncaught TypeError: Cannot read property 'display' of undefined"
Я думаю что это какая то проблема с DOM, но не могу решить какая, сможет кто помочь?
<!DOCTYPE html>
<html>
<head>
<title>Кальклятор</title>
<link rel="stylesheet" href="Style.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<header>
<p><a href="index.html"><img src="webLogo.png" height="100" alt="webLogo" class="picture" ></a></p>
<div class ="radius" id="navig">
<h1>Основы Web-технологий</h1>
<nav>
<ul class="navigation">
<li><a href="index.html">Главная</a></li>
<li><a href="Web.html">Web-технологии</a>
<ul>
<li><a href="html5.html">HTML5</a></li>
<li><a href="CSS3.html">CSS3</a></li>
<li><a href="JavaScript.html">JavaScript</a></li>
</ul>
</li>
<li><a href="calculator.html">Калькулятор</a></li>
<li><a href="test.html">Тест</a></li>
</ul>
</nav>
</div>
</header>
<div class ="radius indent">
<form name="calculatorForm">
<table class="cul">
<tr>
<td colspan="5"><input type="text" maxlength="40" class="inputBox" name="display"
id="dis" /></td>
</tr>
<tr>
<td><input type="button" value="7" id="seven" /></td>
<td><input type="button" value="8" id="eight" /></td>
<td><input type="button" value="9" id="nine" /></td>
<td><input type="button" value="/" id="divide" /></td>
<td><input type="button" value="C" id="clear" /></td>
</tr>
<tr>
<td><input type="button" value="4" id="four" /></td>
<td><input type="button" value="5" id="five" /></td>
<td><input type="button" value="6" id="six" /></td>
<td><input type="button" value="×" id="multiplication" /></td>
<td><input type="button" value="±" id="plusmin" /></td>
</tr>
<tr>
<td><input type="button" value="1" id="one" /></td>
<td><input type="button" value="2" id="two" /></td>
<td><input type="button" value="3" id="three" /></td>
<td><input type="button" value="-" id="minus" /></td>
<td rowspan="2"><input class="equally" type="submit" value="=" id="design" /></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="0" id="zero" /></td>
<td><input type="button" value="." id="dotID" /></td>
<td><input type="button" value="+" id="plus" /></td>
</tr>
</table>
</form>
</div>
</body>
<script>
var memory = "0" // Память
var current = "0" // Дисплей, текущее значение
var operation = 0 // операции, такие как деление, умножение и т.д.
var MAXLENGTH = 30
document.getElementById("zero").onclick = addDigit('0');
document.getElementById("one").onclick = addDigit("1");
document.getElementById("two").onclick = addDigit("2");
document.getElementById("three").onclick = addDigit("3");
document.getElementById("four").onclick = addDigit("4");
document.getElementById("five").onclick = addDigit("5");
document.getElementById("six").onclick = addDigit("6");
document.getElementById("seven").onclick = addDigit("7");
document.getElementById("eight").onclick = addDigit("8");
document.getElementById("nine").onclick = addDigit("9");
document.getElementById("plusmin").onclick = plusMinus(); //+-
document.getElementById("multiplication").onclick = operate("*");
document.getElementById("divide").onclick = operate("/");
document.getElementById("minus").onclick = operate("-");
document.getElementById("plus").onclick = operate("+");
document.getElementById("design").onclick = calculate(); // =
document.getElementById("dotID").onclick = dot(); // .
document.getElementById("clear").onclick = сlearAll(); // C
document.getElementById("dis").onChange = FixCurrent();
function addDigit(dig) { //ADD A DIGIT TO DISPLAY (keep as 'current')
if (current.indexOf("!") == -1) { //if not already an error
if ( (eval(current) == 0)&& (current.indexOf(".") == -1) ) {
current = dig;
} else {
Current = Current + dig;
}
} else {
current = "Hint! Press 'C'"; //Help out, if error present.
}
if (current.indexOf("e0") != -1) {
var epos = current.indexOf("e");
current = current.substring(0,epos+1) + current.substring(epos+2);
}
if (current.length > MAXLENGTH) {
current = "Aargh! Too long"; //don't allow over MAXLENGTH digits before "." ???
}
document.calculatorForm.display.value = current;
}
function dot() { //PUT IN "." if appropriate.
if ( current.length == 0) { //no leading ".", use "0."
current = "0.";
} else {
if (( current.indexOf(".") == -1)&&( current.indexOf("e") == -1)) {
current = Current + ".";
}
}
document.calculatorForm.display.value = current;
}
function plusMinus() {
if (current.indexOf("e") != -1) {
var epos = current.indexOf("e-");
if (epos != -1) {
current = current.substring(0,1+epos) + current.substring(2+epos); //clip out -ve exponent
} else {
epos = current.indexOf("e");
current = current.substring(0,1+epos) + "-" + current.substring(1+epos); //insert -ve exponent
}
} else {
if (current.indexOf("-") == 0) {
current = current.substring(1);
} else {
current = "-" + current;
}
if ((eval(current) == 0)&& (current.indexOf(".") == -1 )) {
current = "0";
}
}
document.calculatorForm.display.value = current;
}
function clearAll() { //Clear ALL entries!
current = "0";
operation = 0; //clear operation
memory = "0"; //clear memory
document.calculatorForm.display.value = current;
}
function operate(op) { //STORE OPERATION e.g. + * / etc.
if (operation != 0) {
calculate();
}
if (op.indexOf("*") > -1) {
operation = 1;
}
if (op.indexOf("/") > -1) {
operation = 2;
}
if (op.indexOf("+") > -1) {
operation = 3;
}
if (op.indexOf("-") > -1) {
operation = 4;
}
memory = current;
current = "";
document.calculatorForm.display.value = current;
}
function Calculate() { //PERFORM CALCULATION (= button)
if (operation == 1) {
current = eval(memory) * eval(current);
}
if (operation == 2) {
if (eval(current) != 0) {
current = eval(memory) / eval(current)
} else {
current = "Aargh! Divide by zero";
}
}
if (operation == 3) {
current = eval(memory) + eval(current);
}
if (operation == 4) {
current = eval(memory) - eval(current);
}
operation = 0;
memory = "0";
current = current + "";
if (current.indexOf("Infinity") != -1) {
current = "Aargh! Value too big";
}
if (current.indexOf("NaN") != -1) {
current = "Aargh! I don't understand";
}
document.calculatorForm.display.value = current;
// NOTE: if no operation, nothing changes, current is left the same!
}
function FixCurrent() {
Current = document.Calculator.Display.value;
Current = "" + parseFloat(Current);
if (Current.indexOf("NaN") != -1) {
Current = "Aargh! I don't understand";
}
document.calculatorForm.display.value = current;
}
</script>
</html>