PDA

View Full Version : javascript calculator question...


wlandymore
11-16-2005, 12:06 PM
I have a calculator that I'm working on and I have run into a couple of problems....

you can see what I have now, here (http://www.rebekahhiggs.com/images/page2.html)

if you fill in a value and click the calculator image on the first or third cell, it works okay. What isn't working is if you fill in a value in the 6th or 9th cell and hit the calculator. Now this is because I haven't really included them in the function yet, but when I tried that I started getting all sorts of scripting errors.

I was trying to build on what I had and put something like:

if (cell1 != "" && cell2 != "" && cell3 != "" && cell4 != "" &&.....) {then solve for the one value that isn't there}
Then I was going to do that about 9 times so each time it would solve for a different variable.
The only other problem is that the checking I have there to make sure that they filled in at least one variable or make sure they didn't fill them all in, etc., isn't working.
I just get 'unidentified'.

Can anyone tell me what might be a good way to go about writing this so that all four of the calculator buttons will solve for every field if a value is put in next to them, and so the error checking will work?

What I have now is getting complex and obviously doesn't work all that well....

Kalessin
11-16-2005, 06:14 PM
When you get the message "undefined" on clicking a calculator button, it's because you're trying to generate an alert from a variable which you haven't defined yet ;)

Try moving the linesvar complete = "You have entered information in each field. Please remove information from one of these.";
var incomplete = "Please fill in at least two fields";
to before the lineif (!ok) alert(incomplete); // they did not enter at least 2 fieldsthen you should find the feedback a little more helpful...

Kal

wlandymore
11-17-2005, 02:39 PM
Man, did that ever help a lot. :)

After I switched that I was able to write 3 seperate functions so depending on which calculator button they pressed, it would run that function.

It was just the complete and incomplete variables not being defined in the proper order that was messing everything up!

I don't know how I missed that....but thanks for pointing it out.

Kalessin
11-17-2005, 04:44 PM
You're welcome :)