Sample JavaScript Programs
by Tom
Sample #1:
To Computer the Square Root of a Number:
Notes:<html>
All Program names are case sensitive
Programmer-supplied (ie arbitrary) names begin with "Toms..."
eg TomsSqrtPgm
TomsSqrtResult.value
TomsNumIn
TomsSqrtCalcAll other programming names are keywords
eg function, form, value, input, type, name, size, button, document, onClick, etc.
eg "text",
eg Math.sqrtThe <p> .. </p> tags were automatically insert by FrontPage
Definitions:
A "form" is a window (.. is a program ..) which has an associated "value"
A "object" is for example, "input", .. which has a "value"
A "function" is a "method"
<head>
<title>Sample: Tom's Square Root Program</title>
<script language="JavaScript">
function TomsSqrtPgm(form) {
form.TomsSqrtResult.value = Math.sqrt(form.TomsNumIn.value); }
</script>
</head><body>
<h2>Tom's SQRT Calculator</h2><form name="TomsSqrtCalc">
<p>Enter a Number: <input type="text" name="TomsNumIn" value size="7">
<input type="button" value="Click for Ans:" onClick="TomsSqrtPgm(document.TomsSqrtCalc">
<input type="text" name="TomsSqrtResult" value size="7"> </p>
</form></body>
</html>