...

View Full Version : [code] Need help on a html calculator please



Tyler James
05-11-2010, 11:51 PM
Hello I'm not very experienced in coding and was wondering if someone could assist me in making a simple calculator in html.

Instead of just a simple calculator I need one that has a "insert value here" sort of thing. Here's the formula

(Base Time) / (1 + 0.005 * ([[Knights|Foreman Politics Skill]]) + 0.1 * [[Research#Giant's Strength|Giant's Strength Research Level]])

Basicly...

.15 / (1 + 0.005 * _____ ) + 0.1 * _____ = _____

(the ____ being places where the person inserts the numbers)

Its for a game and i'm in the process of making a website, any assistance would be greatly appreciated.

code beginner
05-11-2010, 11:53 PM
you want to learn the basics of javascript. that will get you where you need to go.

Tyler James
05-12-2010, 01:53 AM
Okay thats what ill do :) thank you very much

effpeetee
05-12-2010, 11:04 AM
There is much help here (http://www.exitfegs.co.uk/Sources.html).

Frank

frankle
05-12-2010, 02:25 PM
Here i got something for you

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Calculator</title>
</head>
<style>
input{ width:40px;}
</style>
<body>
<form name="Keypad" action="">
<table width="137" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="137">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="164" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4"><input name="ReadOut" type="text" size="24" value="0" style="width:158px;" /></td>
</tr>
<tr>
<td height="4" colspan="4"></td>
</tr>
<tr>
<td><input name="btnClear" type="Button" value=" C " onclick="Clear()" /></td>
<td><input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()" /></td>
<td><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()" /></td>
<td><input name="btnDivide" type="Button" value=" / " onclick="Operation('/')" /></td>
</tr>
<tr>
<td><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)" /></td>
<td><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)" /></td>
<td><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)" /></td>
<td><input name="btnPercent" type="Button" value=" % " onclick="Percent()" /></td>
</tr>
<tr>
<td><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)" /></td>
<td><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)" /></td>
<td><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)" /></td>
<td><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')" /></td>
</tr>
<tr>
<td><input name="btnOne" type="button" value=" 1 " onclick="NumPressed(1)" /></td>
<td><input name="btnTwo" type="button" value=" 2 " onclick="NumPressed(2)" /></td>
<td><input name="btnThree" type="button" value=" 3 " onclick="NumPressed(3)" /></td>
<td><input name="btnMinus" type="Button" value=" - " onclick="Operation('-')" /></td>
</tr>
<tr>
<td><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)" /></td>
<td><input name="btnDecimal" type="Button" value=" . " onclick="Decimal()" /></td>
<td><input name="btnEquals" type="Button" value=" = " onclick="Operation('=')" /></td>
<td><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')" /></td>
</tr>
</table>
</form>
<script>
var FKeyPad = document.Keypad;
var Accumulate = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num)
{
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else
{
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accumulate += parseFloat(Readout);
else if ( '-' == PendingOp )
Accumulate -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accumulate /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accumulate *= parseFloat(Readout);
else
Accumulate = parseFloat(Readout);
FKeyPad.ReadOut.value = Accumulate;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accumulate = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accumulate);
}
</script>
</body>
</html>

Regards.

Tyler James
05-14-2010, 12:40 AM
doesn't seem to be working its just showing up as a normal calculator.

Thanks anyways ill just learn the old fashion way :).

Mr Travis L
05-14-2010, 03:24 AM
Runescape? And you can also use PHP, thats how I do my calculators. I find PHP to be easier than JavaScrip, thats just me though...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum