I am not very familiar with JavaScript and I'am a little confused with the object oriented peculiarities of it. I am trying to create a Caesar shift using the concepts of objects, methods and properties in JavaScript. I am using an HTML form to take input from user and OnClick return the encoded cipher text to user. This is what I have. I'm pretty much sure about my logic but I guess my object creation and method calls fall through. Am I doing it right?
<head>
<script>
function Caesar(order){
this.order = order;
this.encode = encode;
function encode(input){
this.output = '';
for (var i = 0; i < input.length; i++) {
var this.c = input.charCodeAt(i);
if (this.c >= 65 && this.c <= 90) this.output += String.fromCharCode((this.c - 65 + this.order) % 26 + 65); // Uppercase
else if (this.c >= 97 && this.c <= 122) this.output += String.fromCharCode((this.c - 97 + this.key) % 26 + 97); // Lowercase
else this.output += input.charAt(i);
}
return answer.innerHTML= output;
}
</script></head>
<body>
<form>
Enter Plaintext : <input type = "text" name = "plaintext" id = "plaintext">
Enter Shift: <input type = "text" name = "shift" id = "shift"><br> --How do I get the input from here and create my caesar object and pass the constructor the shift from this text box?
<input type="button" value="Encode" onclick ="encode()"> --How do I call the encode() method with input from the plaintext text box?
</form>
</body></html>