Skip to main content
Inspiring
August 16, 2021
Question

Working with Radio Buttons Individually

  • August 16, 2021
  • 2 replies
  • 1887 views

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.

 

 

 

This topic has been closed for replies.

2 replies

Inspiring
August 20, 2021

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);

 

Thom Parker
Community Expert
Community Expert
August 17, 2021

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
August 17, 2021

Thanks for you reply.

 

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

Please observe this picture.

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!

 

 

Inspiring
August 21, 2021

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;

 


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,