I have an HTML command box that's supposed to execute commands e.g. change stylesheet and stuff like that. I thought I worked some magic, but it doesn't work at all. Here's the HTML with the JS and CSS in it. Feel free to make suggestions or if you think you have an idea.
function checkCommand() {
var tempStyle = document.getElementById('temp-style')
var commandInput = document.getElementById('text-box')
if (commandInput.value == black) {
tempStyle.setAttribute("href", "black.css")
}
if (commandInput.value == orange) {
tempStyle.setAttribute("href", "orange.css")
}
if (commandInput.value == white) {
tempStyle.setAttribute("href", "white.css")
}
if (commandInput.value == windows) {
tempStyle.setAttribute("href", "windows.css")
}
}
#text-box {
font-size: 18px;
width: 500px;
height: 20px;
}
#submit-form {
display: none;
}
<link rel="stylesheet" type="text/css" href="white.css" id="temp-style">
<form id="command-form">
<input type="text" id="text-box" placeholder="Enter Command">
<input type="submit" id="submit-form" onclick="checkCommand()">
</form>
<p><b>Black:</b> Background color changes to black and text color changes to white
<br><b>Orange:</b> Background color changes to orange and text color changes to blue
<br><b>White (Default):</b> Background color changes to white and text color changes to black
<br>
<br><b>Windows:</b> Background image changes to Windows XP Bliss and text color changes to black</p>
EDITS
Sidenote: How come when I apply only the HTML tag it looks great, but when the JS tag is in it tries to turn the whole thing into JS? Not too important, but I have OCD so it's kicking in hard.
commandInput.value === "black"etc. And second, you're not cancelling the form's submit event so the page (appears to) just immediately reload. You should pass the event to the function and callevent.preventDefault();