View Single Post
pichlo's Avatar
Posts: 6,453 | Thanked: 20,983 times | Joined on Sep 2012 @ UK
#10
Originally Posted by pichlo View Post
Actually, the whole thing can be implemented in a simple JavaScript. Let me dig out my HTML course material
Here it is (also in the attachment, only rename .txt to .htm):

HTML Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
function calculate(form) {
  var n = (form.band1.value + form.band2.value) * form.multiplier.value;
  if (n >= 1000000)
    n = n / 1000000 + 'M';
  else if (n >= 1000)
    n = n / 1000 + 'K';
  form.result.value = n + form.tolerance.value;
}
</SCRIPT>
</HEAD>

<BODY>
<H1 ALIGN="center">Resistor Colour Code Calculator</H1>
The following calculator allows you to enter the colours of the bands on a given resistor, and it will then return the resistance value.<P>
For each band set the corresponding colour. When all the colours are correct, the corresponding value will be displayed in the 'Resistance' box.<P>

<FORM NAME="colour">
<TABLE ALIGN="center" WIDTH="80%" BORDER="2">
    <TR ALIGN="center">
        <TD>Band 1</TD>
        <TD>Band 2</TD>
        <TD>Multiplier</TD>
        <TD>Tolerance</TD>
    </TR>
    <TR ALIGN="center">
        <TD>
            <SELECT NAME="band1" ONCHANGE="calculate(colour)">
                <OPTION SELECTED VALUE="0" STYLE="background: black; color: white">Black</OPTION>
                <OPTION VALUE="1" STYLE="background: brown; color: white">Brown</OPTION>
                <OPTION VALUE="2" STYLE="background: red; color: white">Red</OPTION>
                <OPTION VALUE="3" STYLE="background: orange; color: white">Orange</OPTION>
                <OPTION VALUE="4" STYLE="background: yellow; color: black">Yellow</OPTION>
                <OPTION VALUE="5" STYLE="background: green; colour: white">Green</OPTION>
                <OPTION VALUE="6" STYLE="background: blue; color: white">Blue</OPTION>
                <OPTION VALUE="7" STYLE="background: purple; color: white">Purple</OPTION>
                <OPTION VALUE="8" STYLE="background: gray; color: white">Grey</OPTION>
                <OPTION VALUE="9" STYLE="background: white; color: black">White</OPTION>
            </SELECT>
        </TD>
        <TD>
            <SELECT NAME="band2" ONCHANGE="calculate(colour)">
                <OPTION SELECTED VALUE="0" STYLE="background: black; color: white">Black</OPTION>
                <OPTION VALUE="1" STYLE="background: brown; color: white">Brown</OPTION>
                <OPTION VALUE="2" STYLE="background: red; color: white">Red</OPTION>
                <OPTION VALUE="3" STYLE="background: orange; color: white">Orange</OPTION>
                <OPTION VALUE="4" STYLE="background: yellow; color: black">Yellow</OPTION>
                <OPTION VALUE="5" STYLE="background: green; color: white">Green</OPTION>
                <OPTION VALUE="6" STYLE="background: blue; color: white">Blue</OPTION>
                <OPTION VALUE="7" STYLE="background: purple; color: white">Purple</OPTION>
                <OPTION VALUE="8" STYLE="background: gray; color: white">Grey</OPTION>
                <OPTION VALUE="9" STYLE="background: white; color: black">White</OPTION>
            </SELECT>
        </TD>
        <TD>
            <SELECT NAME="multiplier" ONCHANGE="calculate(colour)">
                <OPTION SELECTED VALUE="1" STYLE="background: black; color: white">Black</OPTION>
                <OPTION VALUE="10" STYLE="background: brown; color: white">Brown</OPTION>
                <OPTION VALUE="100" STYLE="background: red; color: white">Red</OPTION>
                <OPTION VALUE="1000" STYLE="background: orange; color: white">Orange</OPTION>
                <OPTION VALUE="10000" STYLE="background: yellow; color: black">Yellow</OPTION>
                <OPTION VALUE="100000" STYLE="background: green; color: white">Green</OPTION>
                <OPTION VALUE="1000000" STYLE="background: blue; color: white">Blue</OPTION>
                <OPTION VALUE="0.1" STYLE="background: gold; color: black">Gold</OPTION>
                <OPTION VALUE="0.01" STYLE="background: silver; color: black">Silver</OPTION>
            </SELECT>
        </TD>
        <TD>
            <SELECT NAME="tolerance" ONCHANGE="calculate(colour)">
                <OPTION SELECTED VALUE="&Omega;  5%" STYLE="background: gold; color; black">Gold</OPTION>
                <OPTION VALUE="&Omega;  10%" STYLE="background: silver; color; black">Silver</OPTION>
                <OPTION VALUE="&Omega;  2%" STYLE="background: red; color; white">Red</OPTION>
                <OPTION VALUE="&Omega;  1%" STYLE="background: brown; color; white">Brown</OPTION>
            </SELECT>
        </TD>
    </TR>
</TABLE>
<BR>
<P ALIGN="center">
Resistance:
<INPUT TYPE="text" NAME="result">
<P ALIGN="center">
<INPUT TYPE="reset">
</FORM>
</BODY>
</HTML>
And here is the online version
Attached Files
File Type: txt resistor.txt (4.5 KB, 79 views)
__________________
Русский военный корабль, иди нахуй!
 

The Following 2 Users Say Thank You to pichlo For This Useful Post: