0 votes
in SoSci Survey (English) by s124078 (245 points)

I am calculating a score (stored in D221_13) and want to display it to participants without decimal places.
Therefore, I created a javascript using Math.round() and I created the internal variable D221_14 to store my rounded score in.

However, when I try to display the score it says "NaN".

This is my code:

<script type="text/javascript">
var score = document.getElementById("D221_14");

score.value = Math.round("D221_13");
// -->

What do I need to change?

1 Answer

+1 vote
by SoSci Survey (309k points)
selected by s124078
Best answer

It may be easer to do that in PHP:

$val = round(value('D221_13'));
put('D221_14', $val);

If you like to do that in JavaScript, you will have to drag the question D221 (at least with the variables 13 und 14) on the page above the JavaScript. And, of course, you need to read from the internal variable:

var scoreA = document.getElementById("D221_13");
var scoreB = document.getElementById("D221_14");
scoreB.value = Math.round(parseFloat(scoreA.value));

but ... better use the PHP code, no need to move that from the server to the browser.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen

Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question