Skip to main content
Known Participant
February 6, 2016
Question

Clear text box

  • February 6, 2016
  • 1 reply
  • 476 views

When selecting a checkbox I want to export the data to a text box. I have this code.

Trigger: Mouse Up

Action: Run a JavaScript

var one = this.getField("Check Box2");

var two = this.getField("Text6");

{two.value=one.value}

When clicked it puts the export data from Check Box2 into Text6. However, if I want to change my selection, it will not allow the new export data to be exported into Text6 as it already has the data from the previous selection in it. Any help on the code to clear Text6 before a selection is made in Check Box2 would be much appreciated.

This topic has been closed for replies.

1 reply

Inspiring
February 6, 2016

Is that code in the Mouse Up event of the "Check Box2" check box, or some other one?

senechiaAuthor
Known Participant
February 6, 2016

It was in the Mouse Up Trigger of the checkbox.

senechiaAuthor
Known Participant
February 6, 2016

You cannot change the value that the check box is set to when it is unchecked. It is fixed at the string "Off". The Mouse Up script of the check box could be:

// Mouse Up script for check box

(function () {

    // Get a reference to the text field

    var f = getField("Text6");

    // Populate the text field with a value depending on the state of this check box

    if (event.target.value !== "Off") {

        f.value = event.target.value;  // Export value of check box

    } else {

        f.value = "Something else";  // replace with whatever you want to display when unchecked

    }

})();

You original script might appear to work as a custom calculation script, but it's not correct.

[Edited to correct typo]


I copied and pasted your code in the checkbox, Mouse Up Trigger and I get this "SyntaxError: unterminated string literal 8:at line 9"