Created
September 30, 2012 04:55
-
-
Save 40/3805890 to your computer and use it in GitHub Desktop.
ohm calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form name="f1"> | |
| <table cellpadding="5" cellspacing="0" border="0" bgcolor="#ffedcf"> | |
| <tr> | |
| <td colspan="4" align="center">Enter two known values and press <b>Solve</b> to | |
| calculate unknowns.</td> | |
| </tr><tr> | |
| <td align="center" width="90"><input type="Text" name="volts" size=5><br>Volts<br> | |
| (Volts)</td> | |
| <td align="center" width="90"><input type="Text" name="ohms" size=5 ><br> | |
| Resistance<br>(Ohms)</td> | |
| <td align="center" width="90"><input type="Text" name="amps" size=5 ><br>Current<br> | |
| (Amps)</td> | |
| <td align="center" width="90"><input type="Text" name="watts" size=5 ><br>Power<br> | |
| (Watts)</td> | |
| </tr><tr> | |
| <td align="center" colspan="2"><input type="button" Value=" Solve " name="solve" onClick="solveform()"></td> | |
| <td align="center" colspan="2"><input type="reset" value=" Reset " name="reset" onClick="document.f1.volts.focus()"></td> | |
| </tr> | |
| </table> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function solveform(){ | |
| var d=document.f1; var v1=d.volts.value; var o1=d.ohms.value; var a1=d.amps.value; var w1=d.watts.value; | |
| if (a1 && o1){w1=Math.pow(a1, 2)*o1; v1=o1*a1;} | |
| else if (a1 && v1){w1=a1*v1; o1=v1/a1;} | |
| else if (v1 && o1){w1=Math.pow(v1, 2)/o1; a1=v1/o1;} | |
| else if (w1 && a1){v1=w1/a1; o1=w1/Math.pow(a1,2);} | |
| else if (w1 && v1){a1=w1/v1; o1=Math.pow(v1,2)/w1;} | |
| else if (a1 && v1){w1=v1*a1; o1=v1/a1;} | |
| else if (w1 && o1){v1=Math.sqrt(w1*o1); a1=Math.sqrt(w1/o1);} | |
| d.amps.value=a1; d.volts.value=v1; d.watts.value=w1; d.ohms.value=o1; | |
| v1=o1=a1=w1=0; | |
| document.f1.reset.focus(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment