Using Javascript to toggle visibility of radio buttons on a PDF form

I've been looking around but haven't come across any information regarding using JavaScript with PDF form applications. If I missed something, I apologize and would appreciate any guidance.

Currently, I have 5 radio buttons that are synchronized - when one is selected, the others should be deselected. My goal is to display specific form cells in a PDF based on which radio button is selected.

Here's where I am at the moment: The script for the radio button is set to mouse-up. When one radio button is selected, Text2 appears as intended. However, even if another radio button is selected, Text2 remains visible until I reselect the initial radio button.

I want to show only certain cells depending on the selected radio button, hiding the rest.

If someone could provide me with a simple example, I can take it from there. Thank you.


if (this.getField("Text2").display == display.hidden)
{
    this.getField("Text2").display = display.visible;
}
else
{
    this.getField("Text2").display = display.hidden;
}

Edit: Grammar issue corrected. Update: This is my current objective.


if (this.SELECTED("Choice4")){
    this.getField("Text4").display = display.visible;
}
else {
    this.getField("Text4").display = display.hidden;
}

Update 2: The previous code did not work either.


if(document.getElementByI("Choice3").checked){
    this.getField("Text4").display = display.visible;
}
else {
    this.getField("Text4").display = display.hidden;
}

Answer №1

To successfully toggle a button within a set of radio buttons (or checkboxes acting as radio buttons), it is essential to first conceal all potential fields that may be displayed and then reveal the corresponding ones based on the selection.

The use of hierarchical field names can greatly simplify this process. All fields that are eligible for display or hiding should share a common root in their name, with the second element aligning with the choice, such as

showfield.option1.myfield

By executing

this.getField("showfield").display = display.hidden

all fields linked to the showfield group will be hidden, and by using

this.getField("showfield.option1").display = display.visible

you can reveal all fields belonging to the option1 subgroup within the showfield group.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can be taken to troubleshoot an AJAX error that does not display any error messages?

Within my ajax code, I have the following: $(document).ready(function(){ $("form input#dodaj").click(function(){ var s = $("form input#zad").val(); var str = "<li>"+s+"</li>"; $.ajax( { type: "GET", ...

Is there a way to remove form field data in Django upon submission?

Currently, I am working on a Django project where users can enter a special discount code during registration to receive discounts. The validation of these codes is functioning correctly, but there is one aesthetic issue that needs attention. If a user ent ...

When making a jQuery ajax request to the Google Maps API, an error is returned stating "SyntaxError:

I'm trying to make an ajax call using jsonp to the Google Maps API v3, but it keeps ending up in the error function. In the Firefox console log, I see the following error message: SyntaxError: invalid label "results" : [ When I click on it, I can se ...

Modify the Navbar color with a sticky-top effect in Bootstrap 4

For my sticky navbar, I utilized the Bootstrap 4 class sticky-top. My preference is for a CSS-based solution rather than JavaScript due to past errors encountered with JS. I aim to have my navbar change to a transparent color when it becomes sticky upon s ...

Using AJAX (jQuery) to call a web method declared in a .cs file that is not tied to any specific aspx or ascx file

After moving a web method from the code-behind file of an ASPX page to another CS file located in the data section (which does not have any associated ASPX page), I encountered an issue with accessing the web method using Ajax. Previously, I accessed the w ...

Sending data from the View to the Controller in a Razor MVC3 application involves passing a model along with

Within my view, there's a form representing my View model with multiple fields. I aim to generate a list of links for pagination purposes that will not only redirect to a specific page but also send the input data from the form along with it. The Java ...

Discover the best method for summing all values within a JSON object that contains multiple unique keys

What is the best way to sum up all values in a JSON object? The object provided below contains values that are in string format and it has different keys. var numbers = { x: "4", y: "6", z: "2" }; The result should be: total ...

Interested in leveraging string functions on the information retrieved from the API?

I am trying to utilize String functions such as slice(x,y), length() on the data received from the API. To achieve this, I first converted the data to a variable called mystr using JSON.stringify(obj), but encountered an issue where the console displayed: ...

Use CodeMirror on an existing div element

My div named "content_editable" is the center of my code editing application. I need it to adhere to specific CSS dimensions, but I also want to integrate CodeMirror syntax highlighting into it. However, following the documentation's instructions does ...

What is a clear indication that a <div> is filled with text?

Picture a scenario where a website contains an element that needs to be filled with random text using JavaScript. Once the div is completely filled, it should reset and begin again. It may sound odd, but the question is: how will the JavaScript determine w ...

Emphasize a checkbox by selecting it when another checkbox is checked

I have a question about checkboxes and highlighting the checkmarks. The issue I am facing is that I have multiple checkboxes with the same ID for different screen resolutions. When I click on the label for "Check 1" it highlights the corresponding checkmar ...

Integrating Project Tango with Ionic and/or Angular in a cutting-edge mobile application

I'm currently working on a mobile app project and I could use some advice. The majority of the app can be developed using angular.js (and possibly ionic) JavaScript technology. However, there is one aspect that requires integration with an API, specif ...

Limiting Velocity in a Two-Dimensional Spacecraft

Like many others diving into the world of programming, I decided to challenge myself with a spaceship game project. At this point, I have successfully incorporated parallax stars and other essential features expected in a space-themed game. The spacecraft ...

Updating a single component within a changing array of objects in React: Best practices

I've got a question regarding React rendering that I need help with. Before I dive into the explanation, here's the link to the relevant code sandbox: https://codesandbox.io/s/list-rerendering-y3iust?file=/src/App.js Here's the situation - ...

Ways to manage numerous AJAX actions within a single HTTP request?

Currently, I am utilizing jQuery to create a multipart web page containing a list of links that are updated through periodic AJAX HTTP requests. Each link on the page is triggered by a timer in JavaScript, causing it to make an HTTP request to its designat ...

Modifying the color of an SVG in real-time and using it as a texture in Three.js

I have been attempting to develop a configurator using three.js, but I am currently stuck at the stage where I need to dynamically change the color of the product. My initial idea was to use an SVG as a texture, modify the fill property of the SVG, and eas ...

Discovering the Nearest Point to the Mouse Cursor using Three JS Ray Casting

Three.js version r85 While using raycasting in Three JS, a list of points is generated, and I am interested in identifying the point closest to the cursor. It appears that the first point returned is typically the one nearest to the camera. Is there a me ...

Determine with jQuery whether the img src attribute is null

My HTML structure is as follows: <div class="previewWrapper" id="thumbPreview3"> <div class="previewContainer"> <img src="" class="photoPreview" data-width="" data-height=""><span>3</span> </div> </div> ...

Once deployed, Google Cloud Function experiences delayed execution

I have implemented a Cloud Function that executes the following steps: retrieving data from an API formatting the retrieved data saving the data in Firestore Here is the code snippet for my implementation: exports.syncItems = functions.https.onRequest((r ...

Read in a CSV document within my JavaScript application

Is there a way to import a CSV file into my program in JavaScript when I know the file path? For instance, if the path to the CSV file is C:/Users/User/example.csv, I want to be able to load it into my program like this: let MY_CSV_FILE = CSV_LOAD("C:/Use ...