# JavaScript series resistor circuit calculator

This is a JavaScript calculator how calculate with the ohm's law the voltage, ampere and the resistance.Its only an example but feel free to copy change or reuse this script. Try it:

 UG-U1 U2 UG-U2 U1 U1+U2 UG RG-R1 R2 RG-R2 R1 R1+R2 RG (UG*R1)/RG U1 (UG*R2)/RG U2 UG/RG IG U1/R1 IG U2/R2 IG (R1*U2)/R2 U1 (R2*U1)/R1 U2 (R2*U1)/U2 R1 (R1*U2)/U1 R2 UG/IG RG UG/RG IG RG*IG UG
Code:
```<script>
function Berechne()
{
if(document.Eg.R1.value != "" && document.Eg.R2.value != "")//RG
{document.Eg.RG.value = 1*document.Eg.R1.value + document.Eg.R2.value*1;
document.getElementById("F0").style.backgroundColor = "#00FF00";
document.getElementById("FF0").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F0").style.backgroundColor = "#FF0000";
document.getElementById("FF0").style.backgroundColor = "#FF0000";
}
if(document.Eg.RG.value != "" && document.Eg.R1.value != "")//R2
{document.Eg.R2.value = 1*document.Eg.RG.value - document.Eg.R1.value*1;
document.getElementById("F1").style.backgroundColor = "#00FF00";
document.getElementById("FF1").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F1").style.backgroundColor = "#FF0000";
document.getElementById("FF1").style.backgroundColor = "#FF0000";
}
if(document.Eg.RG.value != "" && document.Eg.R2.value != "")//R1
{document.Eg.R1.value = 1*document.Eg.RG.value - document.Eg.R2.value*1;
document.getElementById("F2").style.backgroundColor = "#00FF00";
document.getElementById("FF2").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F2").style.backgroundColor = "#FF0000";
document.getElementById("FF2").style.backgroundColor = "#FF0000";
}
if(document.Eg.U1.value != "" && document.Eg.U2.value != "")//UG
{document.Eg.UG.value = 1*document.Eg.U1.value + document.Eg.U2.value*1;
document.getElementById("F3").style.backgroundColor = "#00FF00";
document.getElementById("FF3").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F3").style.backgroundColor = "#FF0000";
document.getElementById("FF3").style.backgroundColor = "#FF0000";
}
if(document.Eg.UG.value != "" && document.Eg.U1.value != "")//U2
{document.Eg.U2.value = 1*document.Eg.UG.value - document.Eg.U1.value*1;
document.getElementById("F4").style.backgroundColor = "#00FF00";
document.getElementById("FF4").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F4").style.backgroundColor = "#FF0000";
document.getElementById("FF4").style.backgroundColor = "#FF0000";
}
if(document.Eg.UG.value != "" && document.Eg.U2.value != "")//U1
{document.Eg.U1.value = 1*document.Eg.UG.value - document.Eg.U2.value*1;
document.getElementById("F5").style.backgroundColor = "#00FF00";
document.getElementById("FF5").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F5").style.backgroundColor = "#FF0000";
document.getElementById("FF5").style.backgroundColor = "#FF0000";
}
//end
if(document.Eg.R1.value != "" && document.Eg.R2.value != ""&& document.Eg.UG.value != "")//U1
{document.Eg.U1.value = (1*document.Eg.UG.value * document.Eg.R1.value*1)/(document.Eg.RG.value);
document.getElementById("F6").style.backgroundColor = "#00FF00";
document.getElementById("FF6").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F6").style.backgroundColor = "#FF0000";
document.getElementById("FF6").style.backgroundColor = "#FF0000";
}
if(document.Eg.R1.value != "" && document.Eg.R2.value != ""&& document.Eg.UG.value != "")//U2
{document.Eg.U2.value = (1*document.Eg.UG.value * document.Eg.R2.value*1)/(document.Eg.RG.value);
document.getElementById("F7").style.backgroundColor = "#00FF00";
document.getElementById("FF7").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F7").style.backgroundColor = "#FF0000";
document.getElementById("FF7").style.backgroundColor = "#FF0000";
}
if(document.Eg.UG.value != "" && document.Eg.RG.value != "")//IG
{document.Eg.IG.value = 1*document.Eg.UG.value / document.Eg.RG.value*1;
document.getElementById("F8").style.backgroundColor = "#00FF00";
document.getElementById("FF8").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F8").style.backgroundColor = "#FF0000";
document.getElementById("FF8").style.backgroundColor = "#FF0000";
}
if(document.Eg.U1.value != "" && document.Eg.R1.value != "")//IG
{document.Eg.IG.value = 1*document.Eg.U1.value / document.Eg.R1.value*1;
document.getElementById("F9").style.backgroundColor = "#00FF00";
document.getElementById("FF9").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F9").style.backgroundColor = "#FF0000";
document.getElementById("FF9").style.backgroundColor = "#FF0000";
}
if(document.Eg.U2.value != "" && document.Eg.R2.value != "")//IG
{document.Eg.IG.value = 1*document.Eg.U2.value / document.Eg.R2.value*1;
document.getElementById("F10").style.backgroundColor = "#00FF00";
document.getElementById("FF10").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F10").style.backgroundColor = "#FF0000";
document.getElementById("FF10").style.backgroundColor = "#FF0000";
}
if(document.Eg.U1.value != "" && document.Eg.R1.value != ""&& document.Eg.R2.value != "")
{document.Eg.U2.value = (document.Eg.R2.value*document.Eg.U1.value)/document.Eg.R1.value;
document.getElementById("F11").style.backgroundColor = "#00FF00";
document.getElementById("FF11").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F11").style.backgroundColor = "#FF0000";
document.getElementById("FF11").style.backgroundColor = "#FF0000";
}
if(document.Eg.U2.value != "" && document.Eg.R1.value != ""&& document.Eg.R2.value != "")
{document.Eg.U1.value = (document.Eg.R1.value * document.Eg.U2.value)/document.Eg.R2.value;
document.getElementById("F12").style.backgroundColor = "#00FF00";
document.getElementById("FF12").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F12").style.backgroundColor = "#FF0000";
document.getElementById("FF12").style.backgroundColor = "#FF0000";
}
if(document.Eg.U1.value != "" && document.Eg.U2.value != ""&& document.Eg.R1.value != "")
{document.Eg.R2.value = (document.Eg.R1.value *document.Eg.U2.value)/document.Eg.U1.value;
document.getElementById("F14").style.backgroundColor = "#00FF00";
document.getElementById("FF14").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F14").style.backgroundColor = "#FF0000";
document.getElementById("FF14").style.backgroundColor = "#FF0000";
}
if(document.Eg.U1.value != "" && document.Eg.U2.value != ""&& document.Eg.R2.value != "")
{document.Eg.R1.value = (document.Eg.R2.value*document.Eg.U1.value)/document.Eg.U2.value;
document.getElementById("F15").style.backgroundColor = "#00FF00";
document.getElementById("FF15").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F15").style.backgroundColor = "#FF0000";
document.getElementById("FF15").style.backgroundColor = "#FF0000";
}
if(document.Eg.UG.value != "" && document.Eg.IG.value != "")
{document.Eg.RG.value=document.Eg.UG.value/document.Eg.IG.value;
document.getElementById("F16").style.backgroundColor = "#00FF00";
document.getElementById("FF16").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F16").style.backgroundColor = "#FF0000";
document.getElementById("FF16").style.backgroundColor = "#FF0000";
}
if(document.Eg.UG.value != "" && document.Eg.RG.value != "")
{document.Eg.IG.value=document.Eg.UG.value/document.Eg.RG.value;
document.getElementById("F17").style.backgroundColor = "#00FF00";
document.getElementById("FF17").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F17").style.backgroundColor = "#FF0000";
document.getElementById("FF17").style.backgroundColor = "#FF0000";
}
if(document.Eg.RG.value != "" && document.Eg.IG.value != "")
{document.Eg.UG.value=document.Eg.IG.value*document.Eg.RG.value;
document.getElementById("F18").style.backgroundColor = "#00FF00";
document.getElementById("FF18").style.backgroundColor = "#00FF00";
}else{
document.getElementById("F18").style.backgroundColor = "#FF0000";
document.getElementById("FF18").style.backgroundColor = "#FF0000";
}
}
</script>

<form name="Eg">
<br>
<label>R1 :</label>
<input type="text" name="R1">
<br>
<label>R2 :</label>
<input type="text" name="R2">
<br>
<label>RG :</label>
<input type="text" name="RG">
<br>
<label>U1 :</label>
<input type="text" name="U1">
<br>
<label>U2 :</label>
<input type="text" name="U2">
<br>
<label>UG :</label>
<input type="text" name="UG">
<br>
<label>IG :</label>
<input type="text" name="IG">
<br>
<input type="button" onclick="javascript:Berechne()" value="Berechne">
<br>
<br>
<table id="tom" width="20%" border="2">
<colgroup>
<col width="4*">
<col width="2*">
<col width="1*">
</colgroup>
<tbody>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F4">UG-U1</td>
<td id="FF4">U2</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F5">UG-U2</td>
<td id="FF5">U1</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F3">U1+U2</td>
<td id="FF3">UG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F0">RG-R1</td>
<td id="FF0">R2</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F2">RG-R2</td>
<td id="FF2">R1</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F1">R1+R2</td>
<td id="FF1">RG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F6">(UG*R1)/RG</td>
<td id="FF6">U1</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F7">(UG*R2)/RG</td>
<td id="FF7">U2</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F8">UG/RG</td>
<td id="FF8">IG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F9">U1/R1</td>
<td id="FF9">IG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F10">U2/R2</td>
<td id="FF10">IG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F12">(R1*U2)/R2</td>
<td id="FF12">U1</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F11">(R2*U1)/R1</td>
<td id="FF11">U2</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F15">(R2*U1)/U2</td>
<td id="FF15">R1</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F14">(R1*U2)/U1</td>
<td id="FF14">R2</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F16">UG/IG</td>
<td id="FF16">RG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F17">UG/RG</td>
<td id="FF17">IG</td>
</tr>
<tr bgcolor="#E1E1E1" onmouseout="this.bgColor='#E1E1E1'" onmouseover="this.bgColor='#CCCCFF'">
<td id="F18">RG*IG</td>
<td id="FF18">UG</td>
</tr>
</tbody>
</table>
</form>```

## One thought on “JavaScript series resistor circuit calculator”

1. AlbertNCashett says:

This piece of writing provides clear idea in favor
of the new users of blogging, that in fact how to do running a blog.