You are not logged in.

#1 2008-06-27 16:22:10

INCSlayer
Member
From: Sweden
Registered: 2007-09-06
Posts: 296
Website

a very simple calculator

hello im making a homepage and id like a calculator on it made in javascript the thing is im not really any good in coding javascript
so i was wondering if anyone could possibly help me
this is a mockup of what i was thinking of :
mockup.png
and if its empty or someone enters a letter instead of a sign it gives a errors message but otherwise it prints the number underneath

im not asking anyone to make this for me but if someone can give me some help in how to make it i would be very grateful (ofc is someone WANTS to make it i wont stop them)

thanks in advance INCSlayer


dovie andi se tovya sagain

Offline

#2 2008-06-27 16:39:33

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: a very simple calculator

JavaScript has function to check if they are a number, for instance IsNaN() to check if it is not a number. [Please have a look at a js reference for function names).

The should be a number() function, too, to convert a string to a number (again, see a reference for exact names), which you can use initially for conversation. Afterwards it's a simple DOM operation to replace the text of some field. OK, simple is a lie, but there are plenty of tutorials on that. That's something like document.getElementById('textfield').data = result; , but please refer to a tutorial for the syntax.

Offline

#3 2008-07-03 21:08:18

Varreon
Member
Registered: 2008-07-03
Posts: 95

Re: a very simple calculator

Rather than recreate the wheel, theres a javascript function eval() that evaluates equations. If something doesn't work, you can write your own function. If you need help I don't mind being pm'd, I've got a bunch of free time lately.

Offline

Board footer

Powered by FluxBB