Difference between revisions of "CalcHowTo"

From CunningWiki
Jump to: navigation, search
m (Created page with "Intro As an electrial engineer I spent a lot of time using and creating excel based calculators. The problem I have is when I or other people make minor changes we rarely ever s...")
 
m (Sample Calculator)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
Intro
 
  
 +
== Intro ==
 
As an electrial engineer I spent a lot of time using and creating excel based calculators. The problem I have is when I or other people make minor changes we rarely ever syncronize our updatse. Eventually we just redesign the calculators from scratch. To try and reduce time I wanted to create them in javascript on a webpage. That way I know I can access it anywhere and update it on any pc.
 
As an electrial engineer I spent a lot of time using and creating excel based calculators. The problem I have is when I or other people make minor changes we rarely ever syncronize our updatse. Eventually we just redesign the calculators from scratch. To try and reduce time I wanted to create them in javascript on a webpage. That way I know I can access it anywhere and update it on any pc.
  
example
+
 
code
+
== Sample Calculator ==
 +
 
 +
 
 +
[http://www.cunningturtle.com/wordpress/wp-content/uploads/2011/12/LED-Resistor-Calc.html Example Calculator]
 +
 
 +
<pre>
 +
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 +
<HTML><HEAD><TITLE>Current Limiting Resistor Calculator</TITLE>
 +
 
 +
<SCRIPT language=JavaScript>
 +
 
 +
function Compute1(form) {
 +
with(Math) {
 +
var Precision= 0;
 +
var Vin= Number(form.Vin.value);
 +
var Vled= Number(form.Vled.value);
 +
var Iled= Number(form.Iled.value);
 +
 +
Rled= (Vin-Vled)/(Iled/1000);
 +
Wresistor= (Vin-Vled)*(Iled/1000);
 +
 +
if(Rled<0) {
 +
alert("the numbers you entered don't make sense!!!");
 +
}
 +
 +
form.Rled.value= Rled.toFixed(Precision);
 +
Precision= 3;
 +
form.Wresistor.value= Wresistor.toFixed(Precision);
 +
}
 +
}
 +
 
 +
</SCRIPT>
 +
 
 +
<META name=GENERATOR content="MSHTML 8.00.6001.19154"></HEAD>
 +
 
 +
      <FORM method=post name=ParamForm action="">
 +
      <TABLE border=1>
 +
        <TBODY>
 +
<TR>
 +
          <TD colSpan=2>
 +
          <P align=center><FONT face=Arial><B>LED Current Limiting Resistor Calc</B></FONT></P></TD></TR>
 +
        <TR>
 +
          <TD><FONT size=3 face=Arial>Voltage Input</FONT></TD>
 +
          <TD><FONT face=Arial><INPUT value=5 size=17 name=Vin> (V)</FONT></TD></TR>
 +
        <TR>
 +
          <TD><FONT face=Arial>LED Voltage</FONT></TD>
 +
          <TD><FONT face=Arial><INPUT value=2.1 size=17 name=Vled> (V)</FONT></TD></TR>
 +
        <TR>
 +
          <TD><FONT face=Arial>LED Current</FONT></TD>
 +
          <TD><FONT face=Arial><INPUT value=20 size=17 name=Iled> (mA)</FONT></TD></TR>
 +
        <TR>
 +
          <TD colSpan=2>
 +
          <P align=center><FONT face=Arial><B>Results</B></FONT></P></TD></TR>
 +
        <TR>
 +
          <TD><FONT face=Arial>Current Limiting Resistor<BR><INPUT size=17 name=Rled>(Ohms)<BR><INPUT onclick=Compute1(document.ParamForm) value="Submit" type=button></FONT></TD>
 +
          <TD><FONT face=Arial>Resistor Power rating<BR><INPUT size=17 name=Wresistor>(Watts)<BR></FONT></TD>
 +
 
 +
</HTML>
 +
 
 +
</pre>

Latest revision as of 15:57, 15 December 2011

Intro

As an electrial engineer I spent a lot of time using and creating excel based calculators. The problem I have is when I or other people make minor changes we rarely ever syncronize our updatse. Eventually we just redesign the calculators from scratch. To try and reduce time I wanted to create them in javascript on a webpage. That way I know I can access it anywhere and update it on any pc.


Sample Calculator

Example Calculator

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Current Limiting Resistor Calculator</TITLE>

<SCRIPT language=JavaScript>

function Compute1(form) {
	with(Math) {
		var Precision= 0;
		var Vin= Number(form.Vin.value);
		var Vled= Number(form.Vled.value);
		var Iled= Number(form.Iled.value);
				
		Rled= (Vin-Vled)/(Iled/1000);
		Wresistor= (Vin-Vled)*(Iled/1000);
		
		if(Rled<0) {
			alert("the numbers you entered don't make sense!!!");
		}
		
		form.Rled.value= Rled.toFixed(Precision);
		Precision= 3;
		form.Wresistor.value= Wresistor.toFixed(Precision);
	}
}

</SCRIPT>

<META name=GENERATOR content="MSHTML 8.00.6001.19154"></HEAD>

      <FORM method=post name=ParamForm action="">
      <TABLE border=1>
        <TBODY>
		<TR>
           <TD colSpan=2>
           <P align=center><FONT face=Arial><B>LED Current Limiting Resistor Calc</B></FONT></P></TD></TR>
        <TR>
          <TD><FONT size=3 face=Arial>Voltage Input</FONT></TD>
          <TD><FONT face=Arial><INPUT value=5 size=17 name=Vin> (V)</FONT></TD></TR>
        <TR>
          <TD><FONT face=Arial>LED Voltage</FONT></TD>
          <TD><FONT face=Arial><INPUT value=2.1 size=17 name=Vled> (V)</FONT></TD></TR>
        <TR>
          <TD><FONT face=Arial>LED Current</FONT></TD>
          <TD><FONT face=Arial><INPUT value=20 size=17 name=Iled> (mA)</FONT></TD></TR>
        <TR>
          <TD colSpan=2>
          <P align=center><FONT face=Arial><B>Results</B></FONT></P></TD></TR>
        <TR>
          <TD><FONT face=Arial>Current Limiting Resistor<BR><INPUT size=17 name=Rled>(Ohms)<BR><INPUT onclick=Compute1(document.ParamForm) value="Submit" type=button></FONT></TD>
          <TD><FONT face=Arial>Resistor Power rating<BR><INPUT size=17 name=Wresistor>(Watts)<BR></FONT></TD>

</HTML>