I'm making a simple data url maker and I'm wondering why the code for my clear button isn't working, when other sections with the exact same code are working.
function go() {
var string = document.getElementById("input").value;
var encodedString = btoa(string);
document.getElementById("output").value = "data:text/html;base64," + encodedString;
}
function copy() {
var copyText = document.getElementById("output");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
}
function clear() {
document.getElementById("output").value = "";
document.getElementById("input").value = "";
}
var input = document.getElementById("input");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("go").click();
}
});
button {
font-family: 'Baloo 2', cursive;
background-color: lightgrey;
}
input {
font-family: 'Baloo 2', cursive;
}
<link href="https://fonts.googleapis.com/css?family=Baloo+2&display=swap" rel="stylesheet">
<input id="input" type="text" size="160" placeholder="HTML here" value="">
<button onclick="clear()">🞪</button>
<button id="go" onclick="go()">Convert</button>
<br><br>
<input type="text" placeholder="Output here" id="output" size="160">
<button onclick="copy()">Copy text</button>
Near the bottom, the function called 'clear' isn't working. When I hit the button which calls that function, nothing happens.
However, I'm using the exact same code in the function 'go', which is working.
`, we have CSS, you're using it, so add margin/padding where appropriate. – Mike 'Pomax' Kamermans Mar 22 '20 at 01:46