<!-- SIMPLE CALCULATOR --> <!-- This goes in the HEAD of the html file --> <script language="javascript" type="text/javascript"> <!-- Copyright 2002, Sandeep Gangadharan --> <!-- For more free scripts go to http://sivamdesign.com/scripts/ --> <!-- function getSum() { if (document.calc.choice.selectedIndex==0) { document.calc.theSum.value = document.calc.num1.value + ' + ' + document.calc.num2.value; } if (document.calc.choice.selectedIndex==1) { document.calc.theSum.value = document.calc.num1.value + ' - ' + document.calc.num2.value; } if (document.calc.choice.selectedIndex==2) { document.calc.theSum.value = document.calc.num1.value + ' * ' + document.calc.num2.value; } if (document.calc.choice.selectedIndex==3) { document.calc.theSum.value = document.calc.num1.value + ' / ' + document.calc.num2.value; } } function calcIt() { document.calc.resulter.value = eval(document.calc.theSum.value); } function forError() { if ((document.calc.num1.value=="") || (document.calc.num2.value=="")) document.calc.theSum.value=""; } function info() { alert('Simple Calculator\n\nCopyright © 2002 Sandeep Gangadharan!'); } //--> </script> <!-- This goes in the HEAD of the html file --> <body bgcolor="ffffff"> <form name="calc"> <table align="center" border="0" bgcolor="#c0c0c0" width="310" cellspacing="0" cellpadding="2"> <tr> <td bgcolor="#000080" colspan="2"> <font size="1" face="ms sans serif, verdana, arial, helvetica, sans-serif" color="#ffffff"> <b>Simple Calculator</b> </font> </td> <td align="right" bgcolor="#000080"> <input type="button" value=" i " style="font-size: 9pt" onClick="info()" /> </td> </tr> <tr> <td align="center"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Input 1</b> </font> </td> <td align="center"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Symbol</b> </font> </td> <td align="center"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Input 2</b> </font> </td> </tr> <tr> <td align="center"> <input type="text" name="num1" size="10" style="text-align: center" onChange="getSum()" /> </td> <td align="center"> <select name="choice" onChange="getSum()" style="color: #ff0000"> <option value="+">&nbsp; + &nbsp;</option> <option value="-">&nbsp; - &nbsp;</option> <option value="*">&nbsp; * &nbsp;</option> <option value="/">&nbsp; / &nbsp;</option> </select> </td> <td align="center"> <input type="text" name="num2" size="10" style="text-align: center" onChange="getSum()" /> </td> </tr> <tr> <td align="center"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Equation</b> </font> </td> <td align="center"> &nbsp; </td> <td align="center"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Result</b> </font> </td> </tr> <tr> <td align="center"> <input type="text" name="theSum" size="14" style="text-align: center" /> </td> <td align="center"> <input type="button" style="font-size: 9pt; color: #ff0000" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" onClick="forError();calcIt()" /> </td> <td align="center"> <input type="text" name="resulter" size="14" style="text-align: right" /> </td> </td> </tr> </table> </form>