<html>
<head>
<title>add characters test</title>
<script language="JavaScript">
function myCalc(){
var myLetters = new Array(" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z");
var myNumbers = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
var myPreAddends = document.myForm.myInput.value;
var myLowerCase = myPreAddends.toLowerCase();
var mySum = 0
for(i=0; i<myLowerCase.length; i++) {
myAddend = myLowerCase.charAt(i);
for (x=0; x<myLetters.length; x++) {
if (myAddend == myLetters[x]) {
myAddend = myNumbers[x];
}
}
mySum=mySum + myAddend
}
document.myForm.myResult.value = mySum;
}
function checkLength() {
var InputCheck = document.myForm.myInput.value
if (InputCheck.length > 15) {
alert('Only 15 characters please!');
}
}
</script>
</head>
<body>
<form name="myForm" onsubmit="myCalc(); return false;">
<p>Please enter up to 15 letters (words, phrases, etc):
<input name="myInput" onkeyup="checkLength()">
<input type="submit" value="Calculate!" name="submit">
<hr>
If a=1, b=2, c=3, etc, then your letters add up to:<br>
<input name="myResult">
</form>
</body>
</html>
|