Added ability to insert comments
This commit is contained in:
59
fillcomments.js
Normal file
59
fillcomments.js
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
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 parsed = JSON.parse(data);
|
||||
|
||||
const div = document.getElementById(id);
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user