Skip to main content
Known Participant
May 18, 2018
Answered

Checkbox once clicked, populate multiple fields - Javascript

  • May 18, 2018
  • 1 reply
  • 879 views

I am trying to make a script where once a checkbox is clicked, it take information from two field, then each populates to it's designated area. And if the checkbox is unchecked, it removes that information. So far, I have a script that can take information from one field to another. I posted the code below.

if (getField("Box1").value=="Yes")

this.getField("profile").value = this.getField("Landmark").value;

if (getField("Box1").value=="Off")

this.getField("profile").value = "";

So how would I attempt this? I posted the code of how I thought it could work below.

if (getField("Box1").value=="Yes")

this.getField("profile").value = this.getField("Landmark").value;

this.getField("main house").value = this.getField("Landmark Price").value;

if (getField("Box1").value=="Off")

this.getField("profile").value = "";

this.getField("main house").value = "";

Basically, when the checkbox is checked, I want field "Landmark" to populate to field "profile" as well have field "Landmark Price" populate to field "main house". Then when the checkbox is unchecked, clear the fields "profile" and "main house".

This topic has been closed for replies.
Correct answer Bernd Alheit

Use blocks of commands:

if ( ... ) {

  command 1

  command 2

  ...

}

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
May 18, 2018

Use blocks of commands:

if ( ... ) {

  command 1

  command 2

  ...

}

Known Participant
May 18, 2018

That worked. Thanks!!!