PDA

View Full Version : Calculator variables



funkysoulbrotha
03-24-2011, 11:07 PM
Hi,

I'm trying to make a calculator application; with a few differences.

I have a text field with a numberpad below it, I got the numbers to show up in the text field, but am unsure as to how when I hit the enter button - it would store them in a variable?...I am also wondering as to how it would store current value and then allow me to input another value(maybe on the next page) and either subtract or add to it(the first value that is stored).

I am also wondering how to get a decimal point in place(need it for currency).

Any help would be greatly appreciated!


Here is my code:


<html>
<head>
<script type = "text/javascript">
function decPoint(str){
if (str.indexOf('.') == -1) str += ".";
var decNum = str.substring(str.indexOf('.')+1, str.length);
if (decNum.length > 2)
{
alert("Invalid more than 2 digits after decimal")
}
else {
alert("Valid no")
}
}

var ent = document.write(document.getElementById("curamt").value);


</script>
</head>

<body border = "1"; color = "blue";>
<div id = "cur">
<p>amount is: <script>document.getElementById("amount").innerHTML = ent);</script>
</p>


<b>Please type in price of item:</b>
<form name = "calculator">
<table border = "1"; color = "blue";>
<tr>
<td colspan = "3" width="75%" align = "center">
<input type = "tel" id = "curamt" name = "tinput" maxlength="4" size="6">
</td>
</tr>

<table>
<tr>

<td><input type = "button" name = "one" value = " 1 " onclick = "calculator.tinput.value += '1'"></td>
<td><input type = "button" name = "two" value = " 2 " onclick = "calculator.tinput.value += '2'"></td>
<td><input type = "button" name = "three" value = " 3 " onclick = "calculator.tinput.value += '3'"></td>
</tr>
<tr>
<td><input type = "button" name = "four" value = " 4 " onclick = "calculator.tinput.value += '4'"></td>
<td><input type = "button" name = "five" value = " 5 " onclick = "calculator.tinput.value += '5'"></td>
<td><input type = "button" name = "six" value = " 6 " onclick = "calculator.tinput.value += '6'"></td>
</tr>
<tr>
<td><input type = "button" name = "seven" value = " 7 " onclick = "calculator.tinput.value += '7'"></td>
<td><input type = "button" name = "eight" value = " 8 " onclick = "calculator.tinput.value += '8'"></td>
<td><input type = "button" name = "nine" value = " 9 " onclick = "calculator.tinput.value += '9'"></td>
</tr>
<tr>
<td><input type = "reset" name = "clear" value = " c " onclick = "calculator.tinput.value = ''"></td>
<td><input type = "button" name = "zero" value = " 0 " onclick = "calculator.tinput.value += '0'"></td>
<td><input type = "submit" id = "amount" name = "enter" value = " e " onsubmit = "ent(); return false;"></td>
</tr>
</table>

</table>
</form>
</div>
</body>

</html>