View Full Version : Memory Storage Function of a Calculator

10-13-2003, 09:11 AM
Im trying to make a memory storage button on my calculator to work. I need tohave what ever is inside the text box to go into memory. then be able to recall it whenever i need it. Then when i no longer need the that particular number dump memory back to zero. I have most of everything typed up please take a look at it for me and post how you would go about making something. And if you have the extra time explain to me why you would do that. Thanks and I appreciate any and all suggestions.
<!-- Hide from Incompatible Browsers
var inputString = " " ;
function updateString(value) {
inputString += value;
document.Calculator.Input.value = inputString;
// Stop Hiding Incompatible Browsers -->
<!-- Hide from Incompatible Browsers
var memoryString = " ";
// Stop Hiding from Incompatible Browsers -->
<BODY bgcolor="maroon">
<DIV ALIGN="center">
<FORM NAME="Calculator">
<INPUT TYPE="text" NAME="Input" SIZE="22">
<INPUT TYPE="button" NAME="plus" VALUE=" + " onClick="updateString(' + ')">
<INPUT TYPE="button" NAME="minus" VALUE=" - " onClick="updateString(' - ')">
<INPUT TYPE="button" NAME="times" VALUE=" x " onClick="updateString(' * ')">
<INPUT TYPE="button" NAME="div" VALUE=" / " onClick="updateString(' / ')">
<INPUT TYPE="button" NAME="mod" VALUE=" MOD " onClick="updateString(' % ')">
<INPUT TYPE="button" NAME="nine" VALUE=" 9 " onClick="updateString(' 9 ')">
<INPUT TYPE="button" NAME="eight" VALUE=" 8 " onClick="updateString(' 8 ')">
<INPUT TYPE="button" NAME="seven" VALUE=" 7 " onClick="updateString(' 7 ')">
<INPUT TYPE="button" NAME="six" VALUE=" 6 " onClick="updateString(' 6 ')">
<INPUT TYPE="button" NAME="five" VALUE=" 5 " onClick="updateString(' 5 ')">
<INPUT TYPE="button" NAME="four" VALUE=" 4 " onClick="updateString(' 4 ')">
<INPUT TYPE="button" NAME="three" VALUE=" 3 " onClick="updateString(' 3 ')">
<INPUT TYPE="button" NAME="two" VALUE=" 2 " onClick="updateString(' 2 ')">
<INPUT TYPE="button" NAME="one" VALUE=" 1 " onClick="updateString(' 1 ')">
<INPUT TYPE="button" NAME="zero" VALUE=" 0 " onClick="updateString(' 0 ')">
<INPUT TYPE="button" NAME="point" VALUE=" . " onClick="updateString('.')">
<INPUT TYPE="button" NAME="clear" VALUE=" Clear " onClick="Input.value=' '; inputString=''">
<INPUT TYPE="button" NAME="Calc" VALUE=" = " onClick="Input.value=eval(inputString); inputString=' ' ">
<INPUT TYPE="button" NAME="MemoryStore" VALUE=" M " onClick=" ">
<INPUT TYPE="button" NAME="MemoryRecall" VALUE=" MRC " onClick=" ">
<INPUT TYPE="button" NAME="MemoryClear" VALUE=" MC " onClick=" ">

I have no clue, somewheres in this stuff im having a problem with some of the buttons dont work properly. If u see exactly what it is please call it out to me. I have been looking at it this code for quite some time.

Thanks Again.

10-13-2003, 09:41 AM

I would recommend placing a hidden field in that form which will do the following...
MemoryStore: Set the hidden field to the specified value (overwrites previous)
MemoryRecall: Get the value of the hidden field
MemoryClear: Set the hidden field's value to nothing

- PowerPro

10-13-2003, 12:58 PM
But how would I go about setting up a hidden field, most of this code a took from a text book, Its a project Im doing for my JavaScript class. I am in the process of learning what all this is, but most of the students in the class seem to be more advanced in this area than myself. The professor wanted us to find a solution for making anything in the text box in the form remain in memory, the idea of memoryString was given to me by another student but was unable to explain to me what i had to do and the process of going about it. Again I appreciate any and all info, thank you for ur reply, but im still not understanding what to do sorry.

10-13-2003, 08:40 PM
JavaScript class? If it is a class, should you not be learning it on your own?

A hidden form field is just like any other form field except you set the TYPE tag to hidden, and then the user cannot see it. I gave you assistance, I will not provide you code, sorry.

- PowerPro