A Resistor Color Code Calculator

Last week someone asked me to find an application to download that would calculate resistor values from the color code. I did that, but then I thought I could write such an application myself.

I could write it in a number of different languages but I decided to do it in what I think is the ultimate cross platform language, HTML. Since virtually all operating systems have a built in browser, they can all recognize HTML.

Below is the code:

<!DOCTYPE html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN’ ‘http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd’&gt;
<html xmlns=’http://www.w3.org/1999/xhtml’&gt;
<head profile=’http://gmpg.org/xfn/11′&gt;
<title>Resistor Color Code</title>
<style type=’text/css’>
body {margin-left:0;margin-right:0;font:normal normal normal 12px Arial; white-space: pre-wrap}
a{ text-decoration: }
:link { color: rgb(0, 0, 255) }
:visited {color :rgb(100, 0,100) }
:hover { }
:active { }
input,select{font:normal normal normal 15pt Arial; margin: 5px}
#result{width: 50%}
#band1,#band2,#band3,#band4,#band5,{border: none; background: black; width: 5%}
#v0,#v1,#v2,#v3,#v5,#v6,#v7,#v20,#v21,#v22,#v23,#v25,#v26,#v27,#v30,#v31,#v32,#v33,#v35,#v36,#v37,#v40,#v41,#v42,#v43,#v45,#v46,#v47,#v51,#v52,#v55,#v56,#v57{color: white}
</style>
</head>
<body>
<form action=” ” method=”post”>
<select id=”bands” onclick=’tpe();’>
<option>Number of Bands</option>
<option value=”5″>5 bands</option>
<option value=”4″>4 bands</option>
</select>
<select id=”first” onclick=’init();calc(1);’>
<option id=”v0″ value=”0″>Band One</option>
<option id=”v0″ value=”0″>Black</option>
<option id=”v1″ value=”1″>Brown</option>
<option id=”v2″ value=”2″>Red</option>
<option id=”v3″ value=”3″>Orange</option>
<option id=”v4″ value=”4″>Yellow</option>
<option id=”v5″ value=”5″>Green</option>
<option id=”v6″ value=”6″>Blue</option>
<option id=”v7″ value=”7″>Violet</option>
<option id=”v8″ value=”8″>gray</option>
<option id=”v9″ value=”9″>white</option>
</select> <select id=”second” onclick=’calc(2);’>
<option id=”v20″ value=”0″>Band Two</option>
<option id=”v20″ value=”0″>Black</option>
<option id=”v21″ value=”1″>Brown</option>
<option id=”v22″ value=”2″>Red</option>
<option id=”v23″ value=”3″>Orange</option>
<option id=”v24″ value=”4″>Yellow</option>
<option id=”v25″ value=”5″>Green</option>
<option id=”v26″ value=”6″>Blue</option>
<option id=”v27″ value=”7″>Violet</option>
<option id=”v28″ value=”8″>gray</option>
<option id=”v29″ value=”9″>white</option>
</select> <select id=”third” onclick=’calc(3);’>
<option id=”v30″ value=”0″ >Band Three</option>
<option id=”v30″ value=”0″>Black</option>
<option id=”v31″ value=”1″>Brown</option>
<option id=”v32″ value=”2″>Red</option>
<option id=”v33″ value=”3″>Orange</option>
<option id=”v34″ value=”4″>Yellow</option>
<option id=”v35″ value=”5″>Green</option>
<option id=”v36″ value=”6″>Blue</option>
<option id=”v37″ value=”7″>Violet</option>
<option id=”v38″ value=”8″>gray</option>
<option id=”v39″ value=”9″>white</option>
</select> <select id=”fourth” onclick=’calc(4);’>
<option id=”v40″ value=”0″>Band Four</option>
<option id=”v40″ value=”0″>Black</option>
<option id=”v41″ value=”1″>Brown</option>
<option id=”v42″ value=”2″>Red</option>
<option id=”v43″ value=”3″>Orange</option>
<option id=”v44″ value=”4″>Yellow</option>
<option id=”v45″ value=”5″>Green</option>
<option id=”v46″ value=”6″>Blue</option>
<option id=”v47″ value=”7″>Violet</option>
<option id=”v48″ value=”8″>gray</option>
<option id=”v49″ value=”9″>white</option>
<option id=”v490″ value=”0″>gold</option>
<option id=”v491″ value=”1″>silver</option>
</select> <select id=”fifth” onclick=’calc(5);’>
<option id=”v51″ value=”1″>Band Five</option>
<option id=”v51″ value=”1″ >Brown</option>
<option id=”v52″ value=”2″ >Red</option>
<option id=”v55″ value=”5″ >Green</option>
<option id=”v56″ value=”6″ >Blue</option>
<option id=”v57″ value=”7″ >Violet</option>
<option id=”v58″ value=”8″ >Gray</option>
</select>
<input type=”text” id=”result” name=”result” value=”result” /><input type=”text” id=”input” name=”input” value=”resistance” /> <select id=”percentage”>
<option id=”v60″ value = “+- 10%”>10%</option>
<option id=”v61″ value = “+- 5%”>5%</option>
<option id=”v62″ value = “+- 2%”>2%</option>
<option id=”v63″ value = “+- 1%”>1%</option>
<option id=”v64″ value = “+- 0.5%”>0.5%</option>
<option id=”v65″ value = “+- 0.25%”>0.25%</option>
<option id=”v66″ value = “+- 0.1%”>0.1%</option>
<option id=”v67″ value = “+- 0.05%”>0.05%</option>
</select><br />
<input type=”text” id=”band1″ name=”band1″ value=”” /><input type=”text” id=”band2″ name=”band2″ value=”” /><input type=”text” id=”band3″ name=”band3″ value=”” /><input type=”text” id=”band4″ name=”band4″ value=”” /><input type=”text” id=”band5″ name=”band5″ value=”” /><input type=”button” id = “button” value = “Reset” onclick = ‘reset();’ />
</form>
<script type=”text/javascript”>
var sum;var vu = “v10”; var tol; var bnd; var perc;
function init() {
document.getElementById(“v0″).style.backgroundColor=”black”;
document.getElementById(“v1″).style.backgroundColor=”brown”;
document.getElementById(“v2″).style.backgroundColor=”red”;
document.getElementById(“v3″).style.backgroundColor=”orange”;
document.getElementById(“v4″).style.backgroundColor=”yellow”;
document.getElementById(“v5″).style.backgroundColor=”green”;
document.getElementById(“v6″).style.backgroundColor=”blue”;
document.getElementById(“v7″).style.backgroundColor=”purple”;
document.getElementById(“v8″).style.backgroundColor=”gray”;
document.getElementById(“v9″).style.backgroundColor=”white”;
document.getElementById(“v20″).style.backgroundColor=”black”;
document.getElementById(“v21″).style.backgroundColor=”brown”;
document.getElementById(“v22″).style.backgroundColor=”red”;
document.getElementById(“v23″).style.backgroundColor=”orange”;
document.getElementById(“v24″).style.backgroundColor=”yellow”;
document.getElementById(“v25″).style.backgroundColor=”green”;
document.getElementById(“v26″).style.backgroundColor=”blue”;
document.getElementById(“v27″).style.backgroundColor=”purple”;
document.getElementById(“v28″).style.backgroundColor=”gray”;
document.getElementById(“v29″).style.backgroundColor=”white”;
document.getElementById(“v30″).style.backgroundColor=”black”;
document.getElementById(“v31″).style.backgroundColor=”brown”;
document.getElementById(“v32″).style.backgroundColor=”red”;
document.getElementById(“v33″).style.backgroundColor=”orange”;
document.getElementById(“v34″).style.backgroundColor=”yellow”;
document.getElementById(“v35″).style.backgroundColor=”green”;
document.getElementById(“v36″).style.backgroundColor=”blue”;
document.getElementById(“v37″).style.backgroundColor=”purple”;
document.getElementById(“v38″).style.backgroundColor=”gray”;
document.getElementById(“v39″).style.backgroundColor=”white”;
document.getElementById(“v40″).style.backgroundColor=”black”;
document.getElementById(“v41″).style.backgroundColor=”brown”;
document.getElementById(“v42″).style.backgroundColor=”red”;
document.getElementById(“v43″).style.backgroundColor=”orange”;
document.getElementById(“v44″).style.backgroundColor=”yellow”;
document.getElementById(“v45″).style.backgroundColor=”green”;
document.getElementById(“v46″).style.backgroundColor=”blue”;
document.getElementById(“v47″).style.backgroundColor=”purple”;
document.getElementById(“v48″).style.backgroundColor=”gray”;
document.getElementById(“v49″).style.backgroundColor=”white”;
document.getElementById(“v490″).style.backgroundColor=”gold”;
document.getElementById(“v491″).style.backgroundColor=”silver”;
document.getElementById(“v51″).style.backgroundColor=”brown”;
document.getElementById(“v52″).style.backgroundColor=”red”;
document.getElementById(“v55″).style.backgroundColor=”green”;
document.getElementById(“v56″).style.backgroundColor=”blue”;
document.getElementById(“v57″).style.backgroundColor=”purple”;
document.getElementById(“v58″).style.backgroundColor=”gray”;
}

function reset() {
sum = 0;
bnd = “0”;
}
function tpe() {
bnd = document.getElementById(“bands”).value;
document.getElementById(“result”).value = bnd;
var inp = document.getElementById(“input”).value;
if (inp != “resistance”) {
perc = document.getElementById(“percentage”);
if (inp.substr(0,1) == “0”) document.getElementById(“band1″).style.backgroundColor=”black”;
if (inp.substr(0,1) == “1”) document.getElementById(“band1″).style.backgroundColor=”brown”;
if (inp.substr(0,1) == “2”) document.getElementById(“band1″).style.backgroundColor=”red”;
if (inp.substr(0,1) == “3”) document.getElementById(“band1″).style.backgroundColor=”orange”;
if (inp.substr(0,1) == “4”) document.getElementById(“band1″).style.backgroundColor=”yellow”;
if (inp.substr(0,1) == “5”) document.getElementById(“band1″).style.backgroundColor=”green”;
if (inp.substr(0,1) == “6”) document.getElementById(“band1″).style.backgroundColor=”blue”;
if (inp.substr(0,1) == “7”) document.getElementById(“band1″).style.backgroundColor=”purple”;
if (inp.substr(0,1) == “8”) document.getElementById(“band1″).style.backgroundColor=”gray”;
if (inp.substr(0,1) == “9”) document.getElementById(“band1″).style.backgroundColor=”white”;
if (inp.substr(1,1) == “0”) document.getElementById(“band2″).style.backgroundColor=”black”;
if (inp.substr(1,1) == “1”) document.getElementById(“band2″).style.backgroundColor=”brown”;
if (inp.substr(1,1) == “2”) document.getElementById(“band2″).style.backgroundColor=”red”;
if (inp.substr(1,1) == “3”) document.getElementById(“band2″).style.backgroundColor=”orange”;
if (inp.substr(1,1) == “4”) document.getElementById(“band2″).style.backgroundColor=”yellow”;
if (inp.substr(1,1) == “5”) document.getElementById(“band2″).style.backgroundColor=”green”;
if (inp.substr(1,1) == “6”) document.getElementById(“band2″).style.backgroundColor=”blue”;
if (inp.substr(1,1) == “7”) document.getElementById(“band2″).style.backgroundColor=”purple”;
if (inp.substr(1,1) == “8”) document.getElementById(“band2″).style.backgroundColor=”gray”;
if (inp.substr(1,1) == “9”) document.getElementById(“band2″).style.backgroundColor=”white”;
if (bnd == “5”) {
if (inp.substr(2,1) == “0”) document.getElementById(“band3″).style.backgroundColor=”black”;
if (inp.substr(2,1) == “1”) document.getElementById(“band3″).style.backgroundColor=”brown”;
if (inp.substr(2,1) == “2”) document.getElementById(“band3″).style.backgroundColor=”red”;
if (inp.substr(2,1) == “3”) document.getElementById(“band3″).style.backgroundColor=”orange”;
if (inp.substr(2,1) == “4”) document.getElementById(“band3″).style.backgroundColor=”yellow”;
if (inp.substr(2,1) == “5”) document.getElementById(“band3″).style.backgroundColor=”green”;
if (inp.substr(2,1) == “6”) document.getElementById(“band3″).style.backgroundColor=”blue”;
if (inp.substr(2,1) == “7”) document.getElementById(“band3″).style.backgroundColor=”purple”;
if (inp.substr(2,1) == “8”) document.getElementById(“band3″).style.backgroundColor=”gray”;
if (inp.substr(2,1) == “9”) document.getElementById(“band3″).style.backgroundColor=”white”
if (inp.length – 3 == 0) document.getElementById(“band4″).style.backgroundColor=”black”;
if (inp.length – 3 == 1) document.getElementById(“band4″).style.backgroundColor=”brown”;
if (inp.length – 3 == 2) document.getElementById(“band4″).style.backgroundColor=”red”;
if (inp.length – 3 == 3) document.getElementById(“band4″).style.backgroundColor=”orange”;
if (inp.length – 3 == 4) document.getElementById(“band4″).style.backgroundColor=”yellow”;
if (inp.length – 3 == 5) document.getElementById(“band4″).style.backgroundColor=”green”;
if (inp.length – 3 == 6) document.getElementById(“band4″).style.backgroundColor=”blue”;
if (inp.length – 3 == 7) document.getElementById(“band4″).style.backgroundColor=”purple”;
if (inp.length – 3 == 8) document.getElementById(“band4″).style.backgroundColor=”gray”;
if (inp.length – 3 == 9) document.getElementById(“band4″).style.backgroundColor=”white”;
if (perc.value == “+- 0.05%”) document.getElementById(“band5″).style.backgroundColor=”gray”;
if (perc.value == “+- 0.1%”) document.getElementById(“band5″).style.backgroundColor=”purple”;
if (perc.value == “+- 0.2%”) document.getElementById(“band5″).style.backgroundColor=”blue”;
if (perc.value == “+- 0.5%”) document.getElementById(“band5″).style.backgroundColor=”green”;
if (perc.value == “+- 1%”) document.getElementById(“band5″).style.backgroundColor=”brown”;
if (perc.value == “+- 2%”) document.getElementById(“band5″).style.backgroundColor=”red”;
}

if (bnd == “4”) {
document.getElementById(“band5″).style.backgroundColor=”white”;
if (inp.length – 2 == 0) document.getElementById(“band3″).style.backgroundColor=”black”;
if (inp.length – 2 == 1) document.getElementById(“band3″).style.backgroundColor=”brown”;
if (inp.length – 2 == 2) document.getElementById(“band3″).style.backgroundColor=”red”;
if (inp.length – 2 == 3) document.getElementById(“band3″).style.backgroundColor=”orange”;
if (inp.length – 2 == 4) document.getElementById(“band3″).style.backgroundColor=”yellow”;
if (inp.length – 2 == 5) document.getElementById(“band3″).style.backgroundColor=”green”;
if (inp.length – 2 == 6) document.getElementById(“band3″).style.backgroundColor=”blue”;
if (inp.length – 2 == 7) document.getElementById(“band3″).style.backgroundColor=”purple”;
if (inp.length – 2 == 8) document.getElementById(“band3″).style.backgroundColor=”gray”;
if (inp.length – 2 == 9) document.getElementById(“band3″).style.backgroundColor=”white”;
if (perc.value == “+- 5%”) {
document.getElementById(“band4″).style.backgroundColor=”gold”;
document.getElementById(“band4”).value = “Gold”;
}
if (perc.value == “+- 10%”) {
document.getElementById(“band4″).style.backgroundColor=”silver”;
document.getElementById(“band4”).value = “Silver”;
}
}

}
}
function calc(idx) {
if (bnd == “5”) {
if (idx == 1){
sum = 100 * parseInt(document.getElementById(“first”).value);
vu = “v” + document.getElementById(“first”).value;
if (vu == “v0”)document.getElementById(“first”).style.backgroundColor=”black”;
if (vu == “v1”)document.getElementById(“first”).style.backgroundColor=”brown”;
if (vu == “v2”)document.getElementById(“first”).style.backgroundColor=”red”;
if (vu == “v3”)document.getElementById(“first”).style.backgroundColor=”orange”;
if (vu == “v4”)document.getElementById(“first”).style.backgroundColor=”yellow”;
if (vu == “v5”)document.getElementById(“first”).style.backgroundColor=”green”;
if (vu == “v6”)document.getElementById(“first”).style.backgroundColor=”blue”;
if (vu == “v7”)document.getElementById(“first”).style.backgroundColor=”purple”;
if (vu == “v8”)document.getElementById(“first”).style.backgroundColor=”gray”;
if (vu == “v9”)document.getElementById(“first”).style.backgroundColor=”white”;
}
if (idx == 2){
sum += 10 * parseInt(document.getElementById(“second”).value);
vu = “v2” + document.getElementById(“second”).value;
if (vu == “v20”)document.getElementById(“second”).style.backgroundColor=”black”
if (vu == “v21”)document.getElementById(“second”).style.backgroundColor=”brown”;
if (vu == “v22”)document.getElementById(“second”).style.backgroundColor=”red”;
if (vu == “v23”)document.getElementById(“second”).style.backgroundColor=”orange”;
if (vu == “v24”)document.getElementById(“second”).style.backgroundColor=”yellow”;
if (vu == “v25”)document.getElementById(“second”).style.backgroundColor=”green”;
if (vu == “v26”)document.getElementById(“second”).style.backgroundColor=”blue”;
if (vu == “v27”)document.getElementById(“second”).style.backgroundColor=”purple”;
if (vu == “v28”)document.getElementById(“second”).style.backgroundColor=”gray”;
if (vu == “v29”)document.getElementById(“second”).style.backgroundColor=”white”;
}
if (idx == 3){
sum += parseInt(document.getElementById(“third”).value);
vu = “v3” + document.getElementById(“third”).value;
if (vu == “v30”)document.getElementById(“third”).style.backgroundColor=”black”
if (vu == “v31”)document.getElementById(“third”).style.backgroundColor=”brown”
if (vu == “v32”)document.getElementById(“third”).style.backgroundColor=”red”;
if (vu == “v33”)document.getElementById(“third”).style.backgroundColor=”orange”;
if (vu == “v34”)document.getElementById(“third”).style.backgroundColor=”yellow”;
if (vu == “v35”)document.getElementById(“third”).style.backgroundColor=”green”;
if (vu == “v36”)document.getElementById(“third”).style.backgroundColor=”blue”;
if (vu == “v37”)document.getElementById(“third”).style.backgroundColor=”purple”;
if (vu == “v38”)document.getElementById(“third”).style.backgroundColor=”gray”;
if (vu == “v39”)document.getElementById(“third”).style.backgroundColor=”white”;
}
if (idx == 4){
if (document.getElementById(“fourth”).value == “0”) sum *= 1;
if (document.getElementById(“fourth”).value == “1”) sum *= 10;
if (document.getElementById(“fourth”).value == “2”) sum *= 100;
if (document.getElementById(“fourth”).value == “3”) sum *= 1000;
if (document.getElementById(“fourth”).value == “4”) sum *= 10000;
if (document.getElementById(“fourth”).value == “5”) sum *= 100000;
if (document.getElementById(“fourth”).value == “6”) sum *= 1000000;
if (document.getElementById(“fourth”).value == “7”) sum *= 10000000;
if (document.getElementById(“fourth”).value == “8”) sum *= 100000000;
if (document.getElementById(“fourth”).value == “9”) sum *= 1000000000;
vu = “v4” + document.getElementById(“fourth”).value;
if (vu == “v40”)document.getElementById(“fourth”).style.backgroundColor=”black”
if (vu == “v41”)document.getElementById(“fourth”).style.backgroundColor=”brown”
if (vu == “v42”)document.getElementById(“fourth”).style.backgroundColor=”red”;
if (vu == “v43”)document.getElementById(“fourth”).style.backgroundColor=”orange”;
if (vu == “v44”)document.getElementById(“fourth”).style.backgroundColor=”yellow”;
if (vu == “v45”)document.getElementById(“fourth”).style.backgroundColor=”green”;
if (vu == “v46”)document.getElementById(“fourth”).style.backgroundColor=”blue”;
if (vu == “v47”)document.getElementById(“fourth”).style.backgroundColor=”purple”;
if (vu == “v48”)document.getElementById(“fourth”).style.backgroundColor=”gray”;
if (vu == “v49”)document.getElementById(“fourth”).style.backgroundColor=”white”;
}
if (idx == 5){
vu = “v5” + document.getElementById(“fifth”).value;
if (vu == “v51”) {
document.getElementById(“fifth”).style.backgroundColor=”brown”
tol = ” +- 1%”;
}
if (vu == “v52”) {
document.getElementById(“fifth”).style.backgroundColor=”red”
tol = ” +- 2%”;
}
if (vu == “v55”) {
document.getElementById(“fifth”).style.backgroundColor=”green”
tol = ” +- 0.5%”;
}
if (vu == “v56”) {
document.getElementById(“fifth”).style.backgroundColor=”blue”
tol = ” +- 0.25%”;
}
if (vu == “v57”) {
document.getElementById(“fifth”).style.backgroundColor=”purple”
tol = ” +- 0.1%”;
}
if (vu == “v58”) {
document.getElementById(“fifth”).style.backgroundColor=”gray”
tol = ” +- 0.05%”;
}
}
} else {
document.getElementById(“fifth”).style.backgroundColor=”white”;
if (idx == 1){
sum = 10 * parseInt(document.getElementById(“first”).value);
vu = “v” + document.getElementById(“first”).value;
if (vu == “v0”)document.getElementById(“first”).style.backgroundColor=”black”;
if (vu == “v1”)document.getElementById(“first”).style.backgroundColor=”brown”;
if (vu == “v2”)document.getElementById(“first”).style.backgroundColor=”red”;
if (vu == “v3”)document.getElementById(“first”).style.backgroundColor=”orange”;
if (vu == “v4”)document.getElementById(“first”).style.backgroundColor=”yellow”;
if (vu == “v5”)document.getElementById(“first”).style.backgroundColor=”green”;
if (vu == “v6”)document.getElementById(“first”).style.backgroundColor=”blue”;
if (vu == “v7”)document.getElementById(“first”).style.backgroundColor=”purple”;
if (vu == “v8”)document.getElementById(“first”).style.backgroundColor=”gray”;
if (vu == “v9”)document.getElementById(“first”).style.backgroundColor=”white”;
}
if (idx == 2){
sum += parseInt(document.getElementById(“second”).value);
vu = “v2” + document.getElementById(“second”).value;
if (vu == “v20”)document.getElementById(“second”).style.backgroundColor=”black”
if (vu == “v21”)document.getElementById(“second”).style.backgroundColor=”brown”;
if (vu == “v22”)document.getElementById(“second”).style.backgroundColor=”red”;
if (vu == “v23”)document.getElementById(“second”).style.backgroundColor=”orange”;
if (vu == “v24”)document.getElementById(“second”).style.backgroundColor=”yellow”;
if (vu == “v25”)document.getElementById(“second”).style.backgroundColor=”green”;
if (vu == “v26”)document.getElementById(“second”).style.backgroundColor=”blue”;
if (vu == “v27”)document.getElementById(“second”).style.backgroundColor=”purple”;
if (vu == “v28”)document.getElementById(“second”).style.backgroundColor=”gray”;
if (vu == “v29”)document.getElementById(“second”).style.backgroundColor=”white”;
}
if (idx == 3){
if (document.getElementById(“third”).value == “0”) sum *= 1;
if (document.getElementById(“third”).value == “1”) sum *= 10;
if (document.getElementById(“third”).value == “2”) sum *= 100;
if (document.getElementById(“third”).value == “3”) sum *= 1000;
if (document.getElementById(“third”).value == “4”) sum *= 10000;
if (document.getElementById(“third”).value == “5”) sum *= 100000;
if (document.getElementById(“third”).value == “6”) sum *= 1000000;
if (document.getElementById(“third”).value == “7”) sum *= 10000000;
if (document.getElementById(“third”).value == “8”) sum *= 100000000;
if (document.getElementById(“third”).value == “9”) sum *= 1000000000;
vu = “v3” + document.getElementById(“third”).value;
if (vu == “v30”)document.getElementById(“third”).style.backgroundColor=”black”
if (vu == “v31”)document.getElementById(“third”).style.backgroundColor=”brown”
if (vu == “v32”)document.getElementById(“third”).style.backgroundColor=”red”;
if (vu == “v33”)document.getElementById(“third”).style.backgroundColor=”orange”;
if (vu == “v34”)document.getElementById(“third”).style.backgroundColor=”yellow”;
if (vu == “v35”)document.getElementById(“third”).style.backgroundColor=”green”;
if (vu == “v36”)document.getElementById(“third”).style.backgroundColor=”blue”;
if (vu == “v37”)document.getElementById(“third”).style.backgroundColor=”purple”;
if (vu == “v38”)document.getElementById(“third”).style.backgroundColor=”gray”;
if (vu == “v39”)document.getElementById(“third”).style.backgroundColor=”white”;
}

if (idx == 4){
vu = “v49” + document.getElementById(“fourth”).value;
if (vu == “v490”) {
document.getElementById(“fourth”).style.backgroundColor=”gold”
tol = ” +- 5%”;
}
if (vu == “v491”) {
document.getElementById(“fourth”).style.backgroundColor=”silver”
tol = ” +- 10%”;
}
}

}
document.getElementById(“result”).value= sum + ” ohms ” + tol;
}
</script>
</body>
</html>

 

It was put together in a short period of time, so it might not be the most efficient code possible, but it works.

There are two possible calculations,  1- create the value from a color code and 2- create a color code from a value. Calculations can be done for either a 4 band or five band resistor.

The first calculation is done with the function calc, while the second is done with tpe.

Below is an example of the first calculation for a five band resistor:

Click image for larger view

5band

and below is an example of the second calculation for a four band resistor

Click image for larger view

4band

To do the first calculation select the number of bands from the top option box and from left to right, select the color from the band option boxes. The result calculation is updated interactively.

To do the reverse calculation, enter the resistance value complete with trailing 0’s in the input box that says “resistance”, select the tolerance value from the option box and then select the number of bands.

A typical band color option box appears as in the image below:

Click image for larger view

option

The option box with the tolerance codes for the five band resistor appears as in the image below:

Click image for larger view

option2

In the second calculation, the multiplier value is obtained by calculating the number of trailing 0’s in the resistor value:

if (inp.length – 3 == 3) document.getElementById(“band4″).style.backgroundColor=”orange”;

The colors for the value bands are obtained by parsing the value string:

if (inp.substr(0,1) == “6”) document.getElementById(“band1″).style.backgroundColor=”blue”;

if (inp.substr(1,1) == “4”) document.getElementById(“band2″).style.backgroundColor=”yellow”;

 

 

 

Leave a comment