Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
Alina Zeiler, Have a look at this snippet, hope it helps👍
5th Jan 2019, 7:18 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 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:
5th Jan 2019, 6:49 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
<textarea id="text-area"></textarea> Following script will get the text written on text area var Eingabe= document.getElementById("text-area").value;
5th Jan 2019, 6:27 PM
Rishi Anand
Rishi Anand - avatar