+ 2
Alina Zeiler,
Have a look at this snippet, hope it helpsđ
https://code.sololearn.com/WQILgrevXBMC/?ref=app
+ 1
Hi Alina Zeiler,
This can be done like Rishi Anand mentioned.
Grab the inserted value of the textarea and validate the input with certain words of/or whole strings.
Match() the inserted values with an if statement via regex to reply with an answer.
function send() {
// Grab to inserted value of input
inputvalue = document.getElementById("chatbotinput").value;
// Output the insert value to another textarea/box
outputvalue = document.getElementById("output").innerHTML = (inputvalue);
// If user inserted these word(s) then answer polite
if (/hey|hallo|bonjour|hi|hoi|hello/ig.test(inputvalue)) {
// If inserted value equals the match, answer to user
document.getElementById("output").innerHTML = ("Good afternoon!");
} else {
document.getElementById("output").innerHTML = ("Nothing to match!");
}
Additional:
https://www.w3schools.com/jsref/jsref_regexp_test.asp
https://www.sololearn.com/discuss/1459545/?ref=app
0
<textarea id="text-area"></textarea>
Following script will get the text written on text area
var Eingabe= document.getElementById("text-area").value;