Hi. Iam making a calculator with javascript.
I want it to have a textarea(content id) and a textbox for results to be displayed (display id)

function calculate()
{
var contentBox = document.getElementById('content');
var displayScreen = document.getElementById('display');
 
// sorry that's all i have
 
}

Thanks

Maybe you need to post a bit more code, or atleast have stab at it. In case you are finding it difficult, I would recommend reading some good books and tutorials.

If you have something concrete, do come back and we would definitely help you out.

its marvelous. Today i was investigating about it, and saw that the js eval function did it all for me. Now the problem is smaller.

I have the calculator in an iframe. And the element where i want the result to be displayed, is out of the frame. See this structure.

-(result pane)
-iframe
--calculator form

So this is pure dom.
when the calculate button is pressed, this happens.

ocalc(form).input(textarea where you type the operations).value(result default variable) = eval((resultpanename).value)

without help...

ocalc.input.value = eval((resultpanename).value)

also, how could i make that if enter is pressed while your typing on input obj, the eval function will be executed?

Enter? You're doing a reverse polish notation calculator?

Frames are evil. Whatever you are planning to do can be very well achieved without the help of frames.

As for the return key detection, here is a small example:

<html>
<head>
<script>
    var ENTER_KEY = 13;

    function myKeyPressed(e)
    {
        if(!e)
            var e = window.event;
        if(e.keycode)
            code = e.keycode;
        else if(e.which)
            code = e.which;

        if(code == ENTER_KEY)
        {
            alert('You pressed the ENTER key');
            //call the function which performs calculation
        }
        else
            alert('Press the correct key');
    }
</script>
</head>
<body>
<form>
    <label>Box</label><input type="text" name="txt" id="txt" onkeypress="javascript:myKeyPressed(event)" />
</form>
</body>
</html>

...It doesn't work...

It doesn't work is pretty vague description. You need to tell me what error or output it gives. BTW, I have tested it on Firefox so you might want to try that out. The event model of IE is pretty broken up.

yes, i use ie

please complete this in order to stop me from bothering with my thread...

shift:shiftKey::enter:________

Try using this:

<html>
<head>
<script>
    var ENTER_KEY = 13;

    function myKeyPressed(e)
    {
        if(!e)
            var e = window.event;
        if(e.keyCode)
            code = e.keyCode;
        else if(e.which)
            code = e.which;

        if(code == ENTER_KEY)
        {
            alert('You pressed the ENTER key');
            return true;
            //call the function which performs calculation
        }
        else
        {
            alert('Press the correct key');
            return false;
        }
    }
</script>
</head>
<body>
<form>
    <label>Box</label><input type="text" name="txt" id="txt" onkeypress="javascript:return myKeyPressed(event)" />
</form>
</body>
</html>

I think iam now done.

Thanks a lot you guyz, i will give yo8u credit, even though i dont think nobody is going to notice.

This is for the famouse german game, ogame.

Thanks for your contribution.

Any kind of credit is appreciated. ;-)

Good luck.

:icon_wink: How do I spend it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.