Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHP: add a download as pdf file button in report page
- How to blend adsense inside your post?
- Formatting my post
- PHPWind-- A PHP forum script applcaition in China
- Promote your Forum/Blog/Website via major search Engines
- Google Adsense forum and pin number
- ActionScript 3.0 demo: create a falling snow in flash CS6
- Datatable export excel wraptext and newline
- Linux, automatically backup MySQL database daily
- phpexcel toggle expand and hide column in EXCEL and summary
Saturday, December 22, 2012
A simple Javascript Caculator demo
A simple JavaScript calculator demo:
1) Design a table, first part title "Calculator", second part form for input button
2) In the form, when a button is clicked. the value is added to the string in outputbox
3) When "=" button is clicked, the string in the output box is evaluated
4) When "reset" button is clicked, the string in the output box is set to empty.
JSCaculator.js:
function calculate (form)
{form.outputbox.value = eval (form.outputbox.value)}
function addString(form, str)
{ form.outputbox.value += str}
function reset(form)
{form.outputbox.value = ""}
JSCaculator.html:
<html>
<head>
<title>A Simple JavaScript Caculator</title>
<script type="text/javascript" src="JSCaculator.js">
</script>
</head>
<body>
<table border="4" bgcolor="#C0C0C0">
<tr>
<th><tt>
<h2 align="center"><font color="#0000A0">Caculator</font></h2>
</tt></th>
</tr>
<tr align="center">
<th><form name="myform">
<table border="1">
<tr><td colspan="4" align="center">
<input type="text" name="outputbox" size="20">
</td>
</tr>
<tr align="center">
<td><input type="button" value=" 7 " onClick="addString(this.form,'7')">
</td>
<td><input type="button" value=" 8 " onClick="addString(this.form, '8')"></td>
<td><input type="button" value=" 9 " onClick="addString(this.form, '9')"></td>
<td><input type="button" value=" / " onClick="addString(this.form, '/')"></td>
</tr>
<tr align="center">
<td><input type="button" value=" 4 " onClick="addString(this.form, '4')"></td>
<td><input type="button" value=" 5 " onClick="addString(this.form, '5')"></td>
<td><input type="button" value=" 6 " onClick="addString(this.form, '6')"></td>
<td><input type="button" value=" * " onClick="addString(this.form, '*')"></td>
</tr>
<tr align="center">
<td><input type="button" value=" 1 " onClick="addString(this.form, '1')"></td>
<td><input type="button" value=" 2 " onClick="addString(this.form, '2')"></td>
<td><input type="button" value=" 3 " onClick="addString(this.form, '3')"></td>
<td><input type="button" value=" - " onClick="addString(this.form, '-')"></td>
</tr>
<tr align="center">
<td><input type="button" value=" 0 " onClick="addString(this.form, '0')"></td>
<td><input type="button" value=" . " onClick="addString(this.form, '.')"></td>
<td><input type="button" value=" + " onClick="addString(this.form, '+')"></td>
<td><input type="button" value=" % " onClick="addString(this.form, '%')"></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="button" value=" = " onClick="calculate(this.form)"></td>
<td colspan="2">
<input type="button" value="Clear" onClick="reset(this.form)"></td>
</tr>
</table>
</form>
</th>
</tr>
</table>
</body>
</html>
Video for this demo:
Subscribe to:
Post Comments (Atom)
Python Spell Checker Program
ReplyDeletePython remove punctuation from string
PHP import Excel data to MySQL using PHPExcel
How to convert Excel to CSV Python Pandas
How to read data from excel file using Python Pandas
How to install NLTK for Python on Windows 64 bit
How to read data from excel file in Python