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

Explorer ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

Also, this is not correct:

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

It should be:

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines