How do I take this form and execute certain functions when a specific text is entered to trigger the event?
<form id="form">
<input type="text" placeholder="Enter Command" id="text" />
<input type="button" value="Submit" id="submit" />
</form>
function RUN() {
// when run is entered in text field this function is exe
}
function CLOSE() {
// when close is entered in text field this function is exe
}
example commands: RUN and CLOSE
EDIT something i got kinda working:
How do I make multiple commands exe different functions? This works without the second or third command added. Once I add multiple the only one that works is the one at the bottom.
function readCommand() {
let readInput = document.querySelector('#SearchBar').value
// ↓ no .value, it's already here -----------↑
if (readInput === 'RUN') {
// ↑ === vs =
CMDRUN()
} else {
alert(`Not a command`);
}
}
function readCommand() {
let readInput = document.querySelector('#SearchBar').value
// ↓ no .value, it's already here -----------↑
if (readInput === 'CLOSE') {
// ↑ === vs =
CMDCLOSE()
} else {
alert(`Not a command`);
}
}
function CMDRUN() {
alert ("This is an alert dialog box 1");
}
function CMDCLOSE() {
alert ("This is an alert dialog box 2");
}