For some reason, I cannot get my global variable counter to increase, even when it increases within the function I have the count++ occurring in. My outputted results are different between the text outputted within the function and the text outside of it. Any idea what I am doing wrong here? Shouldn’t the count increase on each iteration of the survey.oncomplete function results?
JavaScript
x
70
70
1
Survey
2
.StylesManager
3
.applyTheme("modern");
4
5
var kn2 = "LwrHXqFRN_pszCopTKHF_Q"
6
var kn3 = "exroCUoYl4wVzs7pKU_49w"
7
8
var count = 0
9
10
var keyname = ("kn" + count)
11
12
var mapilink = "https://images.mapillary.com/" + (keyname) + "/thumb-1024.jpg";
13
14
var json = {
15
pages: [
16
{
17
name: "page1",
18
elements: [
19
{
20
type: "image",
21
name: "image",
22
imageLink: (mapilink),
23
imageHeight: 580,
24
imageWidth: 640
25
},
26
{
27
type: "html",
28
name: (keyname),
29
visible: false,
30
html: (keyname)
31
},
32
{
33
type: "rating",
34
name: "Walkability",
35
title: "How walkable does this look to you"
36
},
37
{
38
type: "rating",
39
name: "Saftey",
40
title: "How safe does this look to you"
41
},
42
{
43
type: "rating",
44
name: "Comfortability",
45
title: "How comfortable does this look to you"
46
}
47
]
48
}
49
]
50
}
51
52
window.survey = new Survey.Model(json);
53
54
var username = document.getElementById("user").value;
55
56
survey
57
.onComplete
58
.add(function (result) {
59
count ++;
60
var PID = document.getElementById("user").value;
61
var results = PID + "_" + (keyname) + ":n" + JSON.stringify(result.data, null, 3) + (count) ;
62
document
63
.querySelector('#surveyResult')
64
.textContent = results;
65
survey.clear();
66
survey.render();
67
});
68
69
$("#surveyElement").Survey({model: survey});
70
Advertisement
Answer
Got an answer from a seperate stackexchange post – basically, I needed to wrap everything in more functions.
function outputting function text rather than expected output