Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Working with Radio Buttons Individually

Participant ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Hello everyone!

 

Is it possible to create individual Radio Buttons?

And in case there is one Radio Button only, can I attribute a string value to it, in the following manner,

ommitting the "Choice1" element in its description?

 

Example:

var they = this.getField("Group53").value 

 

If it is not acceptable, what would the best way to do that?

Thanks a lot for you reply in advance.

 

 

 

TOPICS
Create PDFs, How to, PDF forms

Views

126

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 ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Radio button are of course meant to be groupted together, since, they can only be clicked "On", and cannot be clicked "Off". 

But sure, you can use just one. A form reset will turn it off. 

I don't understand what you mean by "Choice1" in it's description. "Choice1" is the radio button's export value. And you can set the export value to anything you want. 

Read This:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

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
Participant ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Thanks for you reply.

 

Let me explain in more details what I´m planning to do.

Please observe this picture.

Imagem.png

I want my student to click on each radio button and choose the options of words that form a meaningful sentence.

In this case, the sentence is: "They have got a new car." 

As you can see, there is an odd word (afternoon) which I expect my student to dismiss. But in case he doesn´t dismiss it, I need a dialog box to pop out and make him review his choice.

The challenge for me is how to make the individual radio buttons to comunicate in a way they recognize

that the words chosen form a meaningful sentence, regardless of the order the student chooses them, and in case my student chooses at any time, the unwanted word, that the alert dialog box pops out.

From your text I understand that perhaps it is better to work with checkboxes, instead of radio buttons.

In this case, is it possible to substitute the "YES" export value in the Option Tab for another word?

I wrote a script that accepts the student´s choice, in case he picks up the right words.

But how can I make my Javascript reject the student´s choice, in case he picks up the unwanted word?

 

Any advice on that will be much appreciated.

Cheers!

 

 

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 ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Yes, you can replace "Yes"  in checkbox export value.

I didn't understand ,do you want alert to pop as soon as student select 'unwanted' checkbox?In that case don't include that checkbox in your script just add code into that checkbox "Mouse UP" event to pop alert if checkbox is checked:

if(event.target.value != "Off")
app.alert("Your message goes here",3);

Also if you want alert if sentence is not correct,you could use regexp to check text field for words and if field contain all words and text is not "They have got a new car." set alert.

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
Participant ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Hi Ms. Nurani,

 

Thanks for the reply and all the valuable tips.

Just to make it clear: I want the program to pop up the alert message only after it has checked the whole sentence, not as soon as the student chooses the unwanted word.

I am researching RegExps now to get a good grasp of what I must do.

Thanks a lot!

 

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

how is it that the script will know when the whole sentence is complete? 

 

 Here's a script that will dynamically build the string. It assumes that the sentence words are the export values of the checkboxes.  Put it in the Custom Calculation script where the sentence will appear.

It also assumes that the checkbox fields are named like this:  "Q1.Chk1", "Q1.Chk2".   This groups all the words for Question 1.  The Chk1, Chk2, etc. part provides the order for the words. Then you can use almost the exact same script for any question that has this same structure.

 

var aQFlds = this.getField("Q1").getArray().sort(function(a,b){return a.name < b.name;});
var strSentence = "";
for(var i=0;i<aQFlds.length;i++)
{
   if(aQFlds.value != "Off")
      strSentence += aQFlds.value;
}
event.value = strSentence;

 

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
Participant ,
Aug 21, 2021 Aug 21, 2021

Copy link to clipboard

Copied

Thanks for teh help and the tips.

I decided to give up the idea of creating a sentence automatically, based on the user´s choice of

words, using checkboxes.

The idea is somewhat simple but the implementation turned a bit complex considering my level

of Javascript at the moment.

So, I decided to go for a simpler solution, also considering time is running short for me.

Anyway, I´m very very thankful for your valuable help, as usual!!

 

Cheers,

 

 

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 ,
Aug 21, 2021 Aug 21, 2021

Copy link to clipboard

Copied

You're moving in the right direction. You've shown that the regular expression for "Check Box1" is correct. According to whats shown in the console, your regular expression will match the characters "new" in the test string.

What is the export value of "Check Box2"  ?   In your code, the export values from both checkboxes need to match "sentence" in order for the alert box to be displayed. 

 

 

 

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
Participant ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

LATEST

Thanks! I don´t have the script with me anymore, but as far as I can remember the value of Check Box2 was "have", as it should be. The challenge was to make the Javascript "wait" for CheckBox1 && CheckBox2 to be checked,

before popping up the "Correct" message.Strangely, the message was being unleashed right after the first Check Box was checked (!!). Somehow, it didn´t work, although it is a rather easy idea.  In future, I may need to use this script again in another exercise and then I expect to be able to solve all its incongruencies and make it work smoothly.

 

Anyway, thanks again for your valuable help and support.

Cheers!

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
Participant ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Hi Ms Nurani,

 

I wrote the following script for the sake of test (I want test the first two checkboxes

only to see how it goes), just to see if the Javascript can locate the Export Value of each

Check Box. 

 

Although it is apparently reading the export values of the check boxes, it is not

responding to the if command that says that the alert will only pop up after 

checkbox1 and checkbox2 are checked. If this condition is accepted I want to add

the other export values (words) that form the whole sentence. But somehow it is working

only for individual checkboxes.

 

Can you kindly take a look at my code and see what I am doing wrong?

 

(I intend to write this code in each Action tab of each Check Box (except for the unwanted word).

 

var sentence = "They have got a new car.";

myRegExp = new RegExp (this.getField("Check Box1").exportValues);
myRegExp2 = new RegExp (this.getField("Check Box2").exportValues);


if((myRegExp.test(sentence)) && (myRegExp2.test(sentence))){

app.alert("It´s working!",2)
}

 

Thanks a lot in advance!

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 ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

The best option for developing code like you want. Is to do the development in the console window. For example, what exactly is returned from the line: myRegExp = new RegExp (this.getField("Check Box1").exportValues);

 

"exportValues" is an array, not a string value.  You should try it out in the console and see what it actually produces. 

 

However, there is no need for a Regular expression. If your looking for the value of the checkbox export in another string, just use the String.indexOf() function. It's much simpler. 

 

if(sentence.indexOf(this.getField("Check Box2").exportValues[0]) >= 0)
   ...

 

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
Participant ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Thanks a lot for your answer.

 

I tried the line of code in my Acrobat debugger and got the following:

andres45888027_0-1629504147455.png

It´s showing a string (regexp). Is that what it was supposed to do?

Anyway, I still need to get the numbers of the array.

Can you give directions on how to get these? 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
Participant ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

var sentence = "They have got a new car.";


if((myRegExp.test(sentence)) && (myRegExp2.test(sentence))){

app.alert("It´s working!",2)
}
myRegExp = new RegExp(this.getField("Check Box1").exportValues);
myRegExp2 = new RegExp(this.getField("Check Box2").exportValues);

 

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