<html> <script language="LiveScript"> <!-- function addChar(input, character) { if(input.value == null || input.value == "0") input.value = character else input.value += character } function deleteChar(input) { input.value = input.value.substring(0, input.value.length - 1) } function changeSign(input) { // could use input.value = 0 - input.value, but let's show off substring if(input.value.substring(0, 1) == "-") input.value = input.value.substring(1, input.value.length) else input.value = "-" + input.value } function compute(form) { form.display.value = eval(form.display.value) } function square(form) { form.display.value = eval(form.display.value) * eval(form.display.value) } function checkNum(str) { for (var i = 0; i < str.length; i++) { var ch = str.substring(i, i+1) if (ch < "0" || ch > "9") { if (ch != "/" && ch != "*" && ch != "+" && ch != "-" && ch != "(" && ch!= ")") { alert("invalid entry!") return false } } } return true } <!-- --> </script> </head> <body bgcolor="white"> <form> <table align="center" bgcolor="black" border="5"> <tr align="center"> <td colspan="4"> <table border="3"> <tr> <td align="center"><input name="display" size="20" value="0" /></td> </tr> </table> </td> </tr> <tr align="center"> <td> <input onclick="addChar(this.form.display, '7')" type="button" value=" 7 " /> </td> <td> <input onclick="addChar(this.form.display, '8')" type="button" value=" 8 " /> </td> <td> <input onclick="addChar(this.form.display, '9')" type="button" value=" 9 " /> </td> <td> <input onclick="addChar(this.form.display, '/')" type="button" value=" / " /> </td> </tr> <tr align="center"> <td> <input onclick="addChar(this.form.display, '4')" type="button" value=" 4 " /> </td> <td> <input onclick="addChar(this.form.display, '5')" type="button" value=" 5 " /> </td> <td> <input onclick="addChar(this.form.display, '6')" type="button" value=" 6 " /> </td> <td> <input onclick="addChar(this.form.display, '*')" type="button" value=" * " /> </td> </tr> <tr align="center"> <td> <input onclick="addChar(this.form.display, '1')" type="button" value=" 1 " /> </td> <td> <input onclick="addChar(this.form.display, '2')" type="button" value=" 2 " /> </td> <td> <input onclick="addChar(this.form.display, '3')" type="button" value=" 3 " /> </td> <td> <input onclick="addChar(this.form.display, '-')" type="button" value=" - " /> </td> </tr> <tr align="center"> <td> <input onclick="addChar(this.form.display, '0')" type="button" value=" 0 " /> </td> <td> <input onclick="addChar(this.form.display, '.')" type="button" value=" . " /> </td> <td> <input onclick="changeSign(this.form.display)" type="button" value=" +/- " /> </td> <td> <input onclick="addChar(this.form.display, '+')" type="button" value=" + " /> </td> </tr> <tr align="center"> <td> <input onclick="addChar(this.form.display, '(')" type="button" value=" ( " /> </td> <td> <input onclick="addChar(this.form.display, ')')" type="button" value=" ) " /> </td> <td> <input onclick="if (checkNum(this.form.display.value)) { square(this.form) }" type="button" value=" sq " /> </td> <td> <input onclick="deleteChar(this.form.display)" type="button" value=" <- " /> </td> </tr> <tr align="center"> <td colspan="2"> <input name="enter" onclick="if (checkNum(this.form.display.value)) { compute(this.form) }" type="button" value=" Envio " /> </td> <td colspan="2"> <input onclick="this.form.display.value = 0 " type="button" value=" C " /> </td> </tr> </table> </form> </body> </html>
CALCULADORA
<script language="LiveScript">
<!--
function addChar(input, character)
{
if(input.value == null || input.value == "0")
input.value = character
else
input.value += character
}
function deleteChar(input)
{
input.value = input.value.substring(0, input.value.length - 1)
}
function changeSign(input)
{
// could use input.value = 0 - input.value, but let's show off substring
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length)
else
input.value = "-" + input.value
}
function compute(form)
{
form.display.value = eval(form.display.value)
}
function square(form)
{
form.display.value = eval(form.display.value) * eval(form.display.value)
}
function checkNum(str)
{
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i+1)
if (ch < "0" || ch > "9") {
if (ch != "/" && ch != "*" && ch != "+" && ch != "-"
&& ch != "(" && ch!= ")") {
alert("invalid entry!")
return false
}
}
}
return true
}
<!-- -->
</script>
</head>
<body bgcolor="white">
<form>
<table align="center" bgcolor="black" border="5">
<tr align="center">
<td colspan="4">
<table border="3">
<tr>
<td align="center"><input name="display" size="20" value="0" /></td>
</tr>
</table>
</td>
</tr>
<tr align="center">
<td>
<input onclick="addChar(this.form. display, '7')" type="button" value=" 7 " />
</td>
<td>
<input onclick="addChar(this.form. display, '8')" type="button" value=" 8 " />
</td>
<td>
<input onclick="addChar(this.form. display, '9')" type="button" value=" 9 " />
</td>
<td>
<input onclick="addChar(this.form. display, '/')" type="button" value=" / " />
</td>
</tr>
<tr align="center">
<td>
<input onclick="addChar(this.form. display, '4')" type="button" value=" 4 " />
</td>
<td>
<input onclick="addChar(this.form. display, '5')" type="button" value=" 5 " />
</td>
<td>
<input onclick="addChar(this.form. display, '6')" type="button" value=" 6 " />
</td>
<td>
<input onclick="addChar(this.form. display, '*')" type="button" value=" * " />
</td>
</tr>
<tr align="center">
<td>
<input onclick="addChar(this.form. display, '1')" type="button" value=" 1 " />
</td>
<td>
<input onclick="addChar(this.form. display, '2')" type="button" value=" 2 " />
</td>
<td>
<input onclick="addChar(this.form. display, '3')" type="button" value=" 3 " />
</td>
<td>
<input onclick="addChar(this.form. display, '-')" type="button" value=" - " />
</td>
</tr>
<tr align="center">
<td>
<input onclick="addChar(this.form. display, '0')" type="button" value=" 0 " />
</td>
<td>
<input onclick="addChar(this.form. display, '.')" type="button" value=" . " />
</td>
<td>
<input onclick="changeSign(this.form. display)" type="button" value=" +/- " />
</td>
<td>
<input onclick="addChar(this.form. display, '+')" type="button" value=" + " />
</td>
</tr>
<tr align="center">
<td>
<input onclick="addChar(this.form. display, '(')" type="button" value=" ( " />
</td>
<td>
<input onclick="addChar(this.form. display, ')')" type="button" value=" ) " />
</td>
<td>
<input onclick="if (checkNum(this.form.display. value))
{ square(this.form) }" type="button" value=" sq " />
</td>
<td>
<input onclick="deleteChar(this.form. display)" type="button" value=" <- " />
</td>
</tr>
<tr align="center">
<td colspan="2">
<input name="enter" onclick="if (checkNum(this.form.display. value))
{ compute(this.form) }" type="button" value=" = " />
</td>
<td colspan="2">
<input onclick="this.form.display. value = 0 " type="button" value=" C " />
</td>
</tr>
</table>
</form>
</body>
</html>
Enlaces: