Ways to reset a form when a checkbox is unchecked

I recently incorporated a checkbox into a PDF form to automatically duplicate address information when checked using the following script on MouseUp event:

getField("addr1").value = getField("addr2").valueAsString;

But now I am looking for a way to reset the same field when the checkbox is unchecked. Would I need to use a function like this:

clearForm(myFormElement.element.elements?
How can I incorporate this function into my existing script?

Answer №1

After some research (thanks to Google), I realized my mistake in coding. The script was placed on the checkbox instead of the text field, causing it to only import text and not clear it on uncheck.

To resolve this issue, I should have custom validated the field intended for text input (addr2) using the following script:

event.value = (getField("CheckBox").value=="Yes") ? getField("addr1").value : "";

Credit goes to try67 for providing guidance on populating a text field when a checkbox is checked.

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

Send an unchangeable list to a component that needs an Array

Just diving into the world of React and learning that using .toJS() is not recommended due to its impact on performance. The dilemma I'm facing is that a third-party component I'm using requires an array as props, while my state is stored as an ...

Angular facing problems with tracking comment counts in Disqus

After successfully setting up the Disqus comments system on my Angular website following the guide at , everything was working fine. However, when attempting to add the Disqus comment count system to my homepage using the code provided at , I encountered a ...

How to Retrieve the Id of an Inserted Document in Node.js and MongoDB

When trying to insert data from nodejs to mangodb, I successfully added a document to the database. However, I am unsure of how to retrieve the ID upon successful insertion. Is there a way to obtain the ID once the insert is successful? This snippet is fr ...

Leveraging Expressjs to act as a proxy for handling cross-origin requests made via AJAX

I'm working on a website that relies entirely on external APIs, without any server-side logic. All data will be retrieved from an external API. The backend server is mainly used for asset management and routing. We've decided to use nodejs with e ...

Utilize JQuery to Extract JSON Data from Django

How can I properly transfer data results from Django to JavaScript in JSON using an AJAX call? In Django, I currently have the following variable: results = {key1:[1,2,3], key2:[[name1,lat1,lng1],[name2,lat2,lng2],[name3,lat3,lng3]]} After suc ...

Tips for Escaping the If/else Trap in Node.js with Express

Currently, I am working on a project using Node.js and Express. I have implemented a logic to handle the response of an AJAX call which queries data from a MongoDB database through its aggregate framework and then processes the retrieved result. Here is t ...

How to transfer identification from one AngularJS page to another

I need help figuring out how to retrieve an ID from the list.html page and use that same ID to display corresponding details on the list-detail.html page. I am new to using angularjs and struggling with getting the details based on the ID. Below is my code ...

What are some possible reasons or solutions for Axios sending a 404 error?

Hi there, I'm completely new to the MERN stack and I'm encountering an issue when trying to post data using Axios and Express. I may have misunderstood something, so here's my problem. I have a form on a page that I am attempting to use to s ...

Uncover the mystery that lies within the unknown depths

Having the JSON data below: var lists = [{ "listId": 1, "permission": "WRITE" }, { "listId": 2, "permission": "WRITE" }, { "listId": 2, "permission": "READ" }, { "listId": 3, "per ...

What is the best way to call a JavaScript function within a PHP echo statement that outputs a <div> element?

Having trouble echoing this PHP code due to issues with single quotes, causing the HTML to end prematurely. Any suggestions on how to fix this? function button($conn){ $sql = "SELECT * FROM table"; $result= mysqli_query($conn, $sql); while($r ...

Conceal DIV containers during the loading of the page, and reveal them only upon the selection of Radio Buttons

In my user interface, I have implemented three radio buttons labeled as "Easy," "Medium," and "Hard." Each button is assigned to a distinct Javascript function that manipulates the visibility of corresponding div elements. The main purpose behind this setu ...

Stop the jQuery custom slide animation when there are no more items to display

I have designed a unique slider for users to view the work process https://i.sstatic.net/FLYne.png When a user clicks the button, the slider will move left or right depending on the button clicked. However, if the user clicks multiple times, the slider ma ...

Utilizing React for Redirecting to an External Site

I came across a solution for redirecting to an external link, which worked for one of my pages. However, the same solution does not seem to be working for a different page, and I'm unsure of the reason why. redirect.jsx: import React from "react"; ...

Is there a way to add a price to an object in JavaScript?

Purchasedata.find(function(err, purchasedatas) { if (err) { return handleError(res, err); } var totalprice = 0; for (var i = 0; i < purchasedatas.length; i++) { findProduct(i, function(i, price) { }); } ...

vue.js: Modifying information through watcher function

Here is the code I am currently using: export default { name: '...', props: ['user'], data() { return { userName: this.user.name } }, watch: { user: (_user) => { th ...

The typing library for Angular does not properly identify the JQueryStatic object

Encountered an issue with the Angular declaration file: Error TS2304: Cannot locate identifier 'JQueryStatic'. The typings for jQuery are installed and properly declare JQueryStatic as an interface. Looking for solutions to resolve this error. ...

Dealing with window event listeners in react: a guide

In my React application, I am trying to open a popup window and handle events like "message," "load," and "close." However, I am facing an issue where none of the events that I have added listeners to are firing... import * as React from 'react'; ...

Discovering uncategorized elements using javascript

Let's say I have a piece of HTML with some content that is not wrapped in any tags, like this: <html> <body> <p>text in a tag</p> other text outside any tag </body> </html> Is there a way to access the untagged el ...

What is the best way to access and display the innerText of elements that have been removed using console

When I call the updateCartTotal() function, my goal is to display in the console the items that have been removed from the shopping cart. Every time I click on the remove button, I want it to show the item and the price. However, instead of displaying the ...

What is the best way to increase the value of a text box with jquery?

How can I increase the value of #hidtr using jQuery? <script type="text/javascript"> $('#hidtr').val(parseInt($('#hidtr').val()+1)); alert($('#hidtr').val()); </script> ...