I have a task and I just don't know how to get this right. There is the html with a Between this I have to put a form with data from a JSON file. I am allowed to write in a .js file (with jQuery) but not in the json or the html file. I want the output to be a form with ul and li and radio buttons. But I can't even get the questions themselves as an output and don't know what to try anymore
the json file:
[
{
id: "cat1",
title: "title 1",
conditional: false,
questions: [
{id: "q1a", title: "question"},
{id: "q1b", title: "question"},
{id: "q1c", title: "question"},
{id: "q1d", title: "question"},
{id: "q1e", title: "question"},
{id: "q1f", title: "question"},
{id: "q1g", title: "question"}
]
},
{
id: "cat2",
title: "title 2",
conditional: false,
questions: [
{id: "q2a", title: "question"},
{id: "q2b", title: "question"}
]
},
{
id: "cat3",
title: "title",
conditional: true,
questions: [
{id: "q3a", title: "question"},
{id: "q3b", title: "question"},
{id: "q3c", title: "question"},
{id: "q3d", title: "question"}
]
}
]
The last category questions must only show when the category is answered yes.
For now I have the .js (jQuery) as:
$.getJSON( "data/questionaire.json", function(data) {
$.each(data, function(key, category) {
var ul = $('<ul />');
$.each(data.categories, function(category,questions) {
ul.append( $('<li />', {text: questions.title}) );
});
$("div #questionnaire").append(ul);
}); });
The HTML around the div:
<div id="leftPanel">
<h1>03 Complaints</h1>
<!-- Questionnaire placeholder -->
<div id="questionnaire">
</div>