почему в поле инпут не сохраняется значение
function calc(){
var str = document.getElementById("number").value;
alert (str);
var n = str.charAt(1);
var x= parseInt(str.charAt(0));
var y = parseInt(str.charAt(2));
alert(n);
alert(x);
alert(y);
switch (n) {
case "+":
sum(x,y);
break;
case "-":
subtraction(x,y);
break;
case "/":
delet(x,y);
break;
case "*":
multiply(x,y);
break;
default:
break;
}
}
function sum (x,y){
document.getElementById('res').value=("hjyh");
}
function subtraction (x,y){
return x-y;
}
function delet (x,y){
return x/y ;
}
function multiply (x,y){
return x*y ;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="calc.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form>
<input type="text" id="number" value=""><br>
<input type="text" id="res" value="" readonly="readonly"><br>
<button id="button" onclick="calc();" >=</button>
</form>
</body>
</html>
|