- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
javascript in printasnwers.pstpl
- JaninaKowalska
- Topic Author
- Offline
- New Member
Less
More
8 years 2 weeks ago #132823
by JaninaKowalska
javascript in printasnwers.pstpl was created by JaninaKowalska
Hi.
I want to change "Print answers" style , so in printanswers.pstpl I've created
<table id="myTable">
</table>
and I've tried to put javascript:
<script type="text/javascript" charset="utf-8">
var x = {numCriteria};
var table = document.getElementById("myTable");
for (var i = 0 ; i<=x-1 ; i++) {
var row = table.insertRow(i);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = "{Kryteriummiernik_SQ1_SQ5.shown}";
cell2.innerHTML = "{Kryteriummiernik_SQ1_SQ6.shown}";
cell3.innerHTML = "{Kryteriummiernik_SQ1_SQ7.shown}";
}
}
</script>
How should I change my code if I want to change SQ1 depending on 'i'.
I've tried cell1.innerHTML = "{Kryteriummiernik_SQ"+(i+1)+"_SQ5.shown}" and "\{Kryteriummiernik_SQ"+(i+1)+"_SQ5.shown\}" but in result I've shown just {Kryteriummiernik_SQ1_SQ5.shown} instead of the answer.
Morover, is it possible to show the answertexts: 'Kryterium i miernik', 'sposob klasyfikacji', 'wynik' as the labels in the table?
LimeSurvey version: 2.50+
Thank in advance.
I want to change "Print answers" style , so in printanswers.pstpl I've created
<table id="myTable">
</table>
and I've tried to put javascript:
<script type="text/javascript" charset="utf-8">
var x = {numCriteria};
var table = document.getElementById("myTable");
for (var i = 0 ; i<=x-1 ; i++) {
var row = table.insertRow(i);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = "{Kryteriummiernik_SQ1_SQ5.shown}";
cell2.innerHTML = "{Kryteriummiernik_SQ1_SQ6.shown}";
cell3.innerHTML = "{Kryteriummiernik_SQ1_SQ7.shown}";
}
}
</script>
How should I change my code if I want to change SQ1 depending on 'i'.
I've tried cell1.innerHTML = "{Kryteriummiernik_SQ"+(i+1)+"_SQ5.shown}" and "\{Kryteriummiernik_SQ"+(i+1)+"_SQ5.shown\}" but in result I've shown just {Kryteriummiernik_SQ1_SQ5.shown} instead of the answer.
Morover, is it possible to show the answertexts: 'Kryterium i miernik', 'sposob klasyfikacji', 'wynik' as the labels in the table?
LimeSurvey version: 2.50+
Thank in advance.
Attachments:
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
8 years 2 weeks ago - 8 years 2 weeks ago #132844
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript in printasnwers.pstpl
The problem is that Expression Manager is parsing the quotes before the page is rendered. Try using a switch statement. Something like this (untested):How should I change my code if I want to change SQ1 depending on 'i'.
Code:
<script type="text/javascript" charset="utf-8"> var x = {numCriteria}; var table = document.getElementById("myTable"); for (var i = 0 ; i<=x-1 ; i++) { var row = table.insertRow(i); var cell1 = row.insertCell(0); var cell2 = row.insertCell(1); var cell3 = row.insertCell(2); switch(i) { case 0: cell1.innerHTML = "{Kryteriummiernik_SQ1_SQ5.shown}"; cell2.innerHTML = "{Kryteriummiernik_SQ1_SQ6.shown}"; cell3.innerHTML = "{Kryteriummiernik_SQ1_SQ7.shown}"; break; case 1: cell1.innerHTML = "{Kryteriummiernik_SQ2_SQ5.shown}"; cell2.innerHTML = "{Kryteriummiernik_SQ2_SQ6.shown}"; cell3.innerHTML = "{Kryteriummiernik_SQ2_SQ7.shown}"; break; case 2: cell1.innerHTML = "{Kryteriummiernik_SQ3_SQ5.shown}"; cell2.innerHTML = "{Kryteriummiernik_SQ3_SQ6.shown}"; cell3.innerHTML = "{Kryteriummiernik_SQ3_SQ7.shown}"; break; case 3: cell1.innerHTML = "{Kryteriummiernik_SQ4_SQ5.shown}"; cell2.innerHTML = "{Kryteriummiernik_SQ4_SQ6.shown}"; cell3.innerHTML = "{Kryteriummiernik_SQ4_SQ7.shown}"; break; } } </script>
As far as I know, here is no Expression manager variable for the array answer text strings so you'll have to hard-code those.Morover, is it possible to show the answertexts: 'Kryterium i miernik', 'sposob klasyfikacji', 'wynik' as the labels in the table?
Code:
<table id="myTable"> <thead> <th>Kryterium i miernik</th> <th>Sposob klasyfikacji</th> <th>Wynik</th> </thead> </table>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 2 weeks ago by tpartner.
The following user(s) said Thank You: JaninaKowalska
The topic has been locked.
- JaninaKowalska
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
8 years 2 weeks ago #132885
by JaninaKowalska
Replied by JaninaKowalska on topic javascript in printasnwers.pstpl
Tony thank You for reply.
Initially I used "if / else if / else" instead of Your solution - "switch" and the result is the same. I have maximum value of i=20 so I thought about other solution with for loop.
Thank You.
Initially I used "if / else if / else" instead of Your solution - "switch" and the result is the same. I have maximum value of i=20 so I thought about other solution with for loop.
I used this solution.Morover, is it possible to show the answertexts: 'Kryterium i miernik', 'sposob klasyfikacji', 'wynik' as the labels in the table?
As far as I know, here is no Expression manager variable for the array answer text strings so you'll have to hard-code those.
<table id="myTable">
<thead>
<th>Kryterium i miernik</th>
<th>Sposob klasyfikacji</th>
<th>Wynik</th>
</thead>
</table>
Thank You.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
8 years 2 weeks ago #132887
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript in printasnwers.pstpl
Yes, IF statements would also work - I find switches more efficient when working with more than 2 or 3 cases and only comparing to a single variable.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.