I have made a program and it prompts the user to input text. Is there a way I can just take user input from the text box and then have the program take and use that text from there? Here's the code so far:
None of your corrections were working because I didn't tell you the what this program does. This program is supposed to take in a letter and then replace it with another letter encrypting the text, so I think that you need to see the entire code to figure this out;
function encodeFunction() { var text = prompt("Enter Text"); document.getElementById("function").innerHTML = LetterChanges(text); } function decodeFunction() { var text = prompt("Enter Text"); document.getElementById("function").innerHTML = LetterChanges(text, false); } function LetterChanges(str, encode = true) { let adjust = 1; if (!encode) { adjust = -1; } } } str = str.toLowerCase(); let strArray = str.split(""); let letterChange = strArray.map(function(value, index, array){ if(str.charCodeAt(index) < 97 || str.charCodeAt(index) > 122){ return value }else{ return String.fromCharCode(str.charCodeAt(index)+adjust) } }); return letterChange.join(""); }
<form> <input type="text" id="EString" name="EString"> <br><br> </form> <button onclick="encodeFunction()">Encode String</button> <button onclick="decodeFunction()">Decode String</button> <p id="function"></p>
In your encode and decode functions, you can change:
var text = prompt("Enter Text");
to
var text = document.getElementById("EString").value;
1.4m articles
1.4m replys
5 comments
57.0k users