<div id="output"></div>
<div id="container">
<input type="text" id="input" value="">
</div>
<!-- jquery for enter key press -->
<script src="https://code.jquery.com/jquery-3.0.0.js" integrity="sha256-jrPLZ+8vDxt2FnE1zvZXCkCcebI/C8Dt5xyaQBjxQIo=" crossorigin="anonymous"></script>
<script>
var questionNum = 0; // keep count of question, used for IF condition.
var question = '<h2>Bitte geben Sie Ihren Namen ein</h2>'; // first question
var output = document.getElementById('output'); // store id="output" in output variable
output.innerHTML = question; // ouput first question
function bot() {
var input = document.getElementById("input").value;
console.log(input);
if (questionNum == 0) {
output.innerHTML = '<h2>Guten Tag Frau/Herr ' + input + '</h2>';// output response
document.getElementById("input").value = ""; // clear text box
question = '<h2>Wie können wir Ihnen helfen?</h2>'; // load next question
setTimeout(timedQuestion, 2000); // output next question after 2sec delay
}
else if (questionNum == 1) {
output.innerHTML = '<h2>Leider verstehe ich Ihre Frage noch nicht.<br />Bitte benutzen Sie das Kontaktformular zur Beantwortung der Frage ' + input + ' </h2>';
document.getElementById("input").value = "";
question = '<h2>Vielen Dank! <a href="http://anwalt-waffenrecht.com/index.php?id=290" alt="Kontakt">Kontakt</a></h2>';
setTimeout(timedQuestion, 5000);
}
}
function timedQuestion() {
output.innerHTML = question;
}
//push enter key (using jquery), to run bot function.
$(document).keypress(function(e) {
if (e.which == 13) {
bot(); // run bot function when enter key pressed
questionNum++; // increase questionNum count by 1
}
});
</script>