User talk:Tinka09

<html> <head> <title>КАЛКУЛАТОР</title> <script language="JavaScript">

 function saveresults() {
  if (document.calculator.results.value.length > 0) {
   document.calculator.firstvalue.value = document.calculator.results.value;
   document.calculator.operator.value = "";
   document.calculator.secondvalue.value = "";
   document.calculator.results.value = "";
  }
 }

 function setvalue(newvalue) {
  if (document.calculator.operator.value.length == 0) {
  document.calculator.firstvalue.value = document.calculator.firstvalue.value + newvalue;
   }
  else {
  document.calculator.secondvalue.value = document.calculator.secondvalue.value + newvalue;
   }
 }
 function setoperator(opervalue) {
   if (document.calculator.firstvalue.value.length == 0) {
   window.alert("You must first enter a value fo X");
  }
   else {
  document.calculator.operator.value = opervalue;
  }
 }
 function clearY() {
  document.calculator.secondvalue.value = "";
  document.calculator.results.value = "";
   }
 function clearall() {
  document.calculator.firstvalue.value = "";
  document.calculator.secondvalue.value = "";
  document.calculator.operator.value = "";
  document.calculator.results.value = "";
  document.calculator.firstvalue.focus();
  }
 function getresults() {
   var X = Number(document.calculator.firstvalue.value);
   var Y = Number(document.calculator.secondvalue.value);
   var success = 'yes';
  switch (document.calculator.operator.value)
  {
  case "+":
   document.calculator.results.value = X + Y;
  break;
  case "-":
   document.calculator.results.value = X - Y;
  break;
  case "*":
   document.calculator.results.value = X * Y;
  break;
  case "/":
   document.calculator.results.value = X / Y;
  break;
  default:
   window.alert("Invalid Operator: " + document.calculator.operator.value);
  success = 'no';
  break;
   }
if (document.calculator.secondvalue.value.length == 0) {
  window.alert("There is NO value fo Y");
 success = 'no';
 }
if (success == 'yes') {
 savehistory();
 }
}
 function savehistory() {
   document.calculator.history.value = document.calculator.history.value
   + ">" + document.calculator.firstvalue.value + " "
   + document.calculator.operator.value + " "
   + document.calculator.secondvalue.value + " = "
   + document.calculator.results.value + "n";
 }
 function memoryclear() {
  document.calculator.memory.value = "";
 }
 function memoryrecall(calcvar) {
   document.calculator.elements[calcvar].value = document.calculator.memory.value;
 }
 function memorystore() {
   document.calculator.memory.value = document.calculator.results.value;
 }
 function memoryadd() {
   var V = Number(document.calculator.memory.value);
   var R = Number(document.calculator.results.value);
  document.calculator.memory.value = V + R;
 }
</script>

</head>

<body onload="document.calculator.firstvalue.focus();">
<center>
<form name="calculator">
<input name="1" type="button" value=" 1 " onclick="setvalue(1);"> <input name="2" type="button" value=" 2 " onclick="setvalue(2);"> <input name="3" type="button" value=" 3 " onclick="setvalue(3);"> <center><input name="reset" type="button" value=" C " onclick="clearall();"></center>
<input name="4" type="button" value=" 4 " onclick="setvalue(4);"> <input name="5" type="button" value=" 5 " onclick="setvalue(5);"> <input name="6" type="button" value=" 6 " onclick="setvalue(6);"> <input name="clearentry" type="button" value="CE" onclick="clearY();" alt="Clear Y value">
<input name="7" type="button" value=" 7 " onclick="setvalue(7);"> <input name="8" type="button" value=" 8 " onclick="setvalue(8);"> <input name="9" type="button" value=" 9 " onclick="setvalue(9);">
<input name="0" type="button" value=" 0 " onclick="setvalue(0);"> <input name="." type="button" value=" . " onclick="setvalue('.');"> <input name="equals" type="button" value=" = " onclick="getresults();"> <input name="save" type="button" value="R>X" onclick="saveresults();">
<input name="addition" type="button" value=" + " onclick="setoperator('+');"> <input name="subtration" type="button" value=" - " onclick="setoperator('-');"> <input name="multiplication" type="button" value=" * "onclick="setoperator('*');"> <input name="division" type="button" value=" / " onclick="setoperator('/');">
Стойност X: <input type="text" name="firstvalue" size=8 maxlength=40>
+ , - , *, / : <input type="text" name="operator" size=1 maxlength=1 onBlur="setoperator(document.calculator.operator.value);">
Стойност Y: <input type="text" name="secondvalue" size=8 maxlength=40 onBlur="getresults();">
Резултат: <input type="text" name="results" size=8 maxlength=80>
История :
<textarea name="history" cols=20 rows=6></textarea>
Функции за запаметяване
M= <input type="text" name="memory" size=8 maxlength=40> <input name="mc" type="button" value=" MC " onclick="memoryclear();"> <input name="mrX" type="button" value=" MRx " onclick="memoryrecall('firstvalue');"> <input name="mrY" type="button" value=" MRy " onclick="memoryrecall('secondvalue');"> <input name="ms" type="button" value=" MS " onclick="memorystore();"> <input name="m+" type="button" value=" M+ " onclick="memoryadd();">
<input name="reset" type="reset" value="Clear All" alt="Clears All elements"> <input name="close" type="button" value="Close" onclick="window.close();">

</form>

</center>

</body> </html>

Document Tags and Contributors

 Contributors to this page: Tinka09
 Last updated by: Tinka09,