a Simple Javascript Calculator
This is a sample introduction to a web page, with a sample Javascript
to calculate P = D (X5 - 1)/(X - 1) + PE*E*X5 where X = (1+G)/(1+R):

When displayed by your browser it'll look like this:

 Current Dividend = \$ Current EPS = \$ Discount Rate (as a percent) = % Earnings Growth Rate (as a percent) = % Estimated P/E Ratio (in 5 years) = Current Stock Price = \$ ... maybe :^)

To get this calculator, you stick the following stuff between <HEAD> and </HEAD>

 Web Page Title goes here

This command (called calc) expects to get a bunch of data (called inputs).

Somewhere in the BODY of the web page (where you want the calculator to appear), stick this:


Current Dividend = \$
Current EPS = \$
Discount Rate (as a percent) = %
Earnings Growth Rate (as a percent) = %
Estimated P/E Ratio (in 5 years) =
Current Stock Price = \$ ... maybe :^)
... where you'll want to change the stuff in red and
and you can call it inputs (or anything else you like), and
the stuff that does all the work (between <HEAD> and </HEAD>) can be called calc (or anything else), and
the Result doesn't have to be called Result. You could call it SAM.

View the source to see how this is done.

For other examples, click here (where you should View the source to see the Javascript).

Explanation (of sorts):
Between
<FORM NAME="inputs">     and     </FORM>
is a ... uh ... FORM and it's called "inputs".
It collects data from the user with statements like
<INPUT TYPE="number"   NAME="D"   SIZE=5   VALUE="0.72">
This set of data is called "inputs" (because that's the name we gave to the FORM).

Then, at the end, it displays a button (with the word Go!) and, when it's clicked, it sends all this "inputs" data to a JavaScript command called "calc", with the statement calc(inputs):
<INPUT TYPE="button"   VALUE="Go !"   SIZE = 5   ONCLICK= "calc(inputs); return true">