66 lines
1.4 KiB
JavaScript
66 lines
1.4 KiB
JavaScript
|
|
function doComments(id,qid) {
|
|
|
|
let survey=document.getElementById("surveyId").value;
|
|
console.log("Survey is:"+survey);
|
|
|
|
let Q1=document.getElementById("location").value;
|
|
let Q2=document.getElementById("level").value;
|
|
let Q3=document.getElementById("gov").value;
|
|
|
|
|
|
// Create the form data object
|
|
const formData = new FormData();
|
|
formData.append('qid', qid);
|
|
formData.append('survey', survey);
|
|
formData.append('Q1', Q1);
|
|
formData.append('Q2', Q2);
|
|
formData.append('Q3', Q3);
|
|
|
|
// Send the form data using fetch
|
|
fetch('get_text_data.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
// Output result
|
|
//console.log(data);
|
|
const recordNo = parseInt(document.getElementById('record_no').textContent, 10);
|
|
if (recordNo <8){
|
|
return;
|
|
}
|
|
|
|
|
|
const parsed = JSON.parse(data);
|
|
|
|
const div = document.getElementById(id);
|
|
console.log(div);
|
|
// Create a new <ul> element
|
|
const ul = document.createElement("ul");
|
|
|
|
parsed.forEach(item => {
|
|
const li = document.createElement("li");
|
|
li.textContent = item.text;
|
|
ul.appendChild(li);
|
|
|
|
console.log(item.text);
|
|
});
|
|
|
|
// Optionally, add some list items
|
|
|
|
|
|
|
|
// Append the <ul> to the div
|
|
div.appendChild(ul);
|
|
|
|
|
|
// Re-enable body, and revert cursor
|
|
return;
|
|
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|