Forum:Javascript calculator

Yet another website that hosted a popular calculator thingy went offline, so I'm thinking about making a more reliable one right here. My last JS project didn't go too well without help, so I'll probably need some on this one as well :)

What I intend to do is something that looks like the pic on the right. There will be several fields (Value 1-x boxes) that accept numbers from users. When users click on Button, the javascript will use specified values in several formulas to display information in the Output box.

Is something like this possible on wikia? Has anyone tried it already, that I could see as an example?

As I understand it, I'll need to create a Form onsubmit Event.

-- 10:14, October 25, 2011 (UTC)


 * It's very much possible. See here for a similar tool. — Sovq 10:21, October 25, 2011 (UTC)


 * I felt like playing around and created something like this - http://jsfiddle.net/YDNqV/. It currently only sums up the values in the fields, but I imagine any math can be done on the values. Of course the styling can be easily modified with CSS afterwards. — Sovq 11:18, October 25, 2011 (UTC)


 * Just what I needed :) Thanks, now it's much easier to figure out. -- 11:48, October 25, 2011 (UTC)


 * Yessss! It's alive! I'll post an update later :) -- 14:38, October 25, 2011 (UTC)

(Update)

I managed to write this calc (javascript and html). It seems to be working correctly, as far as my algorithm goes.

Are there any syntax issues, or did I miss anything? I used the JSLint thingy in jsfiddle, and it doesn't show any errors.

I also used the Inconsolata font for some of the text, since jsfiddle had it and it looked nice. Can everyone see it, or just me? I assumed it works for everyone because I don't have it on my PC. -- 22:13, November 3, 2011 (UTC)


 * It does display some results when clicking the "Calculate" button, so the script is definitely working. Don't ask me if all the math is done right though - I have no clue what it should be. You might want to check if other scripts on your wiki are not in conflict with this one. The previously linked stat calculator on Dead Frontier Wiki broke the new editor's Visual Mode for some time. — Sovq 07:07, November 4, 2011 (UTC)


 * The math is fine :) I'm more concerned about technical stuff like should I add addOnloadHook; kind of things, because I don't fully understand how it all works.


 * It doesn't look like there's any conflict, except that wikia.js isn't working for some reason, so I had to use common.js instead. -- 21:06, November 4, 2011 (UTC)


 * I'm not really that experienced with JavaScript myself, but from what I understand, adding addOnloadHook; would be required if you wanted to execute a function on page load. Since you're already using the jQuery  method (with   event) the function is executed every time you click the   element, so there's no reason to execute the script on page load. But then again I might be completely wrong. What's important is that it works, right? ;) — Sovq 21:35, November 4, 2011 (UTC)


 * True :) -- 01:05, November 5, 2011 (UTC)