basically i am trying to write an html page with javascript init that will display a text box and a button and another text box. you type something in the first text box, then click the button and the letters are all swapped with their correspondingly numbered letters from an array (a is the first letter in the alphabet, so if s is the first value in the array (at index 0), a gets output as s), with upper case characters getting treated as lower case and spaces getting output as spaces.
i am supposed to make use of the unicode values of words by using charCodeAt() but i can't basically make it work. the code is below, the function doSubEncipher() and the first bit of subEncipher() were written already and i have put the rest in myself. The GUI form works but the thing won't output anything no matter what i do.
as i say, don't tell me how to do it because it's supposed to be my own work, but if you happen to bsee where i have gone wrong, then hints or criticisms wouldn't go amiss.
thank you etc in advance!
- Code: Select all
<HTML>
<HEAD>
<SCRIPT>
function subEncipher(aString)
{
var subArray = ['s','c','h','n','i','t','z','e','l','m','o','p','q','r','u','v','w','x','y','a','b','d','f','g','j','k'];
var outString = "";
var codeString = "";
for(var count = 0; count = aString.length; count = count + 1)
{
if (aString.charAt(count) = " ")
{
outString = outString + " ";
}
else
{
codeString = (aString.charCodeAt(count) - 97);
outString = outString + subArray[codeString];
};
return outString
}
function doSubEncipher()
{
var givenString,encodedString;
document.encipher.outputString.value ='';
givenString = document.encipher.inputString.value;
givenString = givenString.toLowerCase();// note that toLowerCase leaves non-alpha characters unchanged
encodedString = subEncipher(givenString);
document.encipher.outputString.value = encodedString;
document.encipher.inputString.focus();// reset focus
}
</SCRIPT>
</HEAD>
<BODY>
<form NAME = "encipher">
Enter String<br>
<INPUT TYPE = "text"
NAME = "inputString"
VALUE = ''>
<br>
<input TYPE = "button"
VALUE = "Encipher"
ONCLICK = "document.encipher.outputString.value = doSubEncipher()">
<br>
<INPUT TYPE = "text"
NAME = "outputString"
VALUE = ''>
</BODY>
</HTML>


