Jump to content
  • 0

Trouble with test calculation and variable passing.



I'm trying to provide the DAST test on my website, and I'm using Caspio as the medium. I've created a WebForm, and each question has its own field in the table, along with the last field, labeled score. Each of the questions has radio button input, with Yes given a value of 1 and No given a value of 0. With the script, which I've copied and edited from a Caspio archive, I'm attempting to add all the values from all of the questions and write the score in the score field. My first problem is that the script is returning a NaN in my table. My script is this:


function calculate()

var q1 = parseFloat(document.forms[0].InsertRecordq1.value);

var q2 = parseFloat(document.forms[0].InsertRecordq2.value);

var q3 = parseFloat(document.forms[0].InsertRecordq3.value);

var q4 = parseFloat(document.forms[0].InsertRecordq4.value);

var q5 = parseFloat(document.forms[0].InsertRecordq5.value);

var q6 = parseFloat(document.forms[0].InsertRecordq6.value);

var q7 = parseFloat(document.forms[0].InsertRecordq7.value);

var q8 = parseFloat(document.forms[0].InsertRecordq8.value);

var q9 = parseFloat(document.forms[0].InsertRecordq9.value);

var q10 = parseFloat(document.forms[0].InsertRecordq10.value);

var q11 = parseFloat(document.forms[0].InsertRecordq11.value);

var q12 = parseFloat(document.forms[0].InsertRecordq12.value);

var q13 = parseFloat(document.forms[0].InsertRecordq13.value);

var q14 = parseFloat(document.forms[0].InsertRecordq14.value);

var q15 = parseFloat(document.forms[0].InsertRecordq15.value);

var q16 = parseFloat(document.forms[0].InsertRecordq16.value);

var q17 = parseFloat(document.forms[0].InsertRecordq17.value);

var q18 = parseFloat(document.forms[0].InsertRecordq18.value);

var q19 = parseFloat(document.forms[0].InsertRecordq19.value);

var q20 = parseFloat(document.forms[0].InsertRecordq20.value);

var score = (q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16 + q17 + q18 + q19 + q20);

document.forms[0].InsertRecordscore.value = Math.round(score);



As you can see, each field is labeled q1-q20 respectively. In a consultation, it was determined that one of fields had a non-numerical value. However, I went through my WebForm several times, and checked all of my tests in the table, and all values were numerical, so the WebForm is functioning correctly. So, I've determined that my problem is definitely in the script, but I lack the knowledge to correct it.

Which brings me to my second problem. After submission, I want to use the 'Display this message' destination, in which I plan to show the tester their score. However, I lack the knowledge to retrieve the score from the prior page, or table if required, and display it. Due to the nature of this test, anonymity is essential, so any identification methods that I know of are unusable, and I'm utterly stuck.

Any advice would be greatly appreciated.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0


Try getElementById instead of forms[0].

function calculate()


var v_q1 = document.getElementById('InsertRecordq1');

var q1 = parseFloat( v_q1.value ,10 );

...........do this for q2-q20.

var score = (q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16 + q17 + q18 + q19 + q20);

document.getElementById('InsertRecordscore').value = Math.round(score);



To show the total score on the last page, you can pick the fields from the picker(a small picker box on the right of the HTML block). So the message on form submission would be something like this:

Your total score is [@InsertRecordscore#].

Hope this helps!


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...