Skip to main content
Inspiring
January 9, 2019
Question

How to make button stop working when radio button question not answered?

  • January 9, 2019
  • 3 replies
  • 285 views

Hi,

I am creating a PDF form survey with yes/no radio button questions. There is one question and "next" button per page that makes the next page appear. The question is called "Q1". I want to make the button do nothing until they answer.

For example, if Q1 was on page 6, this code might keep them on the same page if they don't answer:

var v = this.getField("Q1").valueAsString; 

if (v==" ") this.pageNum = this.pageNum = 5; 

else this.pageNum = 6;

(This doesn't work - it always goes to page 7, even if they didn't respond)

Any ideas on how to fix this?

Thanks!

This topic has been closed for replies.

3 replies

jd44Author
Inspiring
January 9, 2019

Ok, great input - thanks for the help.

Like always, I am developing dirty solutions to simple problems. I don't want to create an alert box because that would be intrusive and this is a sensitive questionaire, so I just want the "next" button to do nothing if they push it without answering. The problem I'm running into is that some pages have several questions (up to three) and so currently I am specifying each possible combination of yes/no answers to allow them to move on to the next page. This page has three yes/no questions (Q16a, Q16b, Q16c):

var v = this.getField("Q16a").valueAsString + this.getField("Q16b").valueAsString + this.getField("Q16c").valueAsString;

if (v=="000" || v=="100" || v=="110" || v=="111" || v=="010" || v=="001" || v=="011" || v=="101") this.pageNum = 23;

I'm sure there is an easier way to check if the fields are not answered - is this where null comes in?

if (v== null) this.pageNum = 23;

Something like that? (I know that doesn't work haha)

Thanks

try67
Community Expert
Community Expert
January 9, 2019

Also, this is not correct:

if (v==" ") this.pageNum = this.pageNum = 5;

It should be:

if (v==" ") this.pageNum = 5;

Thom Parker
Community Expert
Community Expert
January 9, 2019

First, page numbers in the JS model are zero based, so "6" is the 7th page.

Next, if they are pressing the button to move to a new page, there is no need to set the page number in the case where you want them to stay on the page, Only set the page when a change is needed. Also, use an Alert box to inform them they have missed a question.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often