Skip to main content
bmskinner
Participant
January 9, 2024
Answered

Need to validate True or False dropdown box

  • January 9, 2024
  • 1 reply
  • 1335 views

Hi there! I have some True or False questions added to my PDF using the field Dropdown1 (Dropdown2, etc.). I need a way to validate if their answer is correct. How can I accomplish this? 

This topic has been closed for replies.
Correct answer Nesa Nurani

Try something like this in a button as 'Mouse UP' action (Run a JavaScript):

var correct = 0;
for( var i=1; i<=5; i++){
 var drop = this.getField("Dropdown"+i).valueAsString;
 if(i==1 || i==3 || i==5){
  if(drop === "True")
   correct++;}
 else if(i==2 || i==4){
  if(drop === "False")
   correct++;}}

app.alert("User have "+correct+"/5 answers correct.",3 );

1 reply

Nesa Nurani
Community Expert
Community Expert
January 9, 2024

You could use script in a button when clicked it would show alert with field names (or questions) which have correct answer, or it can also list field names (or questions) that are not correct.

bmskinner
bmskinnerAuthor
Participant
January 9, 2024

What script would I use in the button? For example, Dropdown1, Drowdown3, and Dropdown 5 are True answers and the other two are false. How can I pull the data to say the user got 4/5 correct, etc.? Sorry, I'm new to this. 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 9, 2024

Try something like this in a button as 'Mouse UP' action (Run a JavaScript):

var correct = 0;
for( var i=1; i<=5; i++){
 var drop = this.getField("Dropdown"+i).valueAsString;
 if(i==1 || i==3 || i==5){
  if(drop === "True")
   correct++;}
 else if(i==2 || i==4){
  if(drop === "False")
   correct++;}}

app.alert("User have "+correct+"/5 answers correct.",3 );