JSFiddle - React, Tailwind, and code Playground
by Ulrich Bangert
HTML
<form id="Formular1" name="Formular1">
</form>
JavaScript
var config = {
frage1: { text: "Text der 1. Frage?",
options: {
option1: { followup: "frage2", text: "Text der 1. Option" },
option2: { followup: "http://seite1.de/index.html", text: "Text der 2. Option" }
}
},
frage2: { text: "Text der 2. Frage?",
options: {
option1: { followup: "frage3", text: "Text der 1. Option" },
option2: { followup: "http://seite2.de/index.html", text: "Text der 2. Option" }
}
}
};
function buildQuestion(question) {
var rb, frm = $("#Formular1");
frm.empty();
frm.append(config[question].text + "<br>")
for (opt in config[question].options) {
rb = $('<input type="radio" name="Auswahl">');
rb.val(config[question].options[opt].followup);
frm.append(rb);
frm.append(config[question].options[opt].text + "<br>");
rb.click(function () {
if ($(this).val().search("^https?:") == 0) {
window.location = $(this).val();
} else {
buildQuestion($(this).val());
}
});
}
}
buildQuestion("frage1")