Skip to main content
sd0123
Known Participant
July 3, 2018
Answered

Submit button to add +1 in form field

  • July 3, 2018
  • 1 reply
  • 1293 views

(EDITED to clarify question)

I have a group of radio buttons named KAQuestion.1 (export values are either 0 or 1), a Submit1 button, and two fields - CorrectTotal and IncorrectTotal.

If the radio value is 0, submit should trigger 1 to be added to IncorrectTotal

If the radio value is 1, submit should trigger 1 to be added to CorrectTotal

Please help me with the script for the Submit button.  Here's the core of what I'm looking at:

var KAQ = this.getField("KAQuestion.1").value;

if (KAQ == 0)

this.getField("IncorrectAnswerTotal").value = +1;

else

this.getField("CorrectAnswerTotal").value = +1;

I had this script as a calculation on the CorrectTotal, which works, but I don't want the calculation to trigger until the user commits to the submit button

var testFor = "1";

var groups = this.getField("KAQuestion");

var ar = groups.getArray();

var cnt = 0;

for (var i=0; i<ar.length; i++) {

    if (ar.value == testFor) {

        cnt++;

    }

}

event.value = cnt;

Thanks in advance.

This topic has been closed for replies.
Correct answer try67

Use this code:

var KAQ = Number(this.getField("KAQuestion.1").value);

if (KAQ == 0) this.getField("IncorrectAnswerTotal").value = Number(this.getField("IncorrectAnswerTotal").value)+1;

else this.getField("CorrectAnswerTotal").value = Number(this.getField("CorrectAnswerTotal").value)+1;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 3, 2018

Use this code:

var KAQ = Number(this.getField("KAQuestion.1").value);

if (KAQ == 0) this.getField("IncorrectAnswerTotal").value = Number(this.getField("IncorrectAnswerTotal").value)+1;

else this.getField("CorrectAnswerTotal").value = Number(this.getField("CorrectAnswerTotal").value)+1;

sd0123
sd0123Author
Known Participant
July 3, 2018

Thank you so much!  I had just tried the following (which looks close to yours without the Number() designation) before your reply:

var KAQ = this.getField("KAQuestion.1").value;

var subI = this.getField("IncorrectAnswerTotal").value;

var subC = this.getField("CorrectAnswerTotal").value;

if (KAQ == 0)

this.getField("IncorrectAnswerTotal").value = subI +1;

else

this.getField("CorrectAnswerTotal").value = subC +1;

I appreciate you taking the time to reply!