How do I populate a text box based on the state of one of thee radio buttons?

Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

For example:

If radio button 1 = true textbox 1 = "option1"

If radio button 1 = false textbox 1 =""

If radio button 2 = true textbox 1 = "option2"

If radio button 2 = false textbox 1 =""

If radio button 3 = true textbox 1 = "option3"

If radio button 3 = false textbox 1 =""

all of the radio buttons = false the Textbox 1 should = ""

This might work....??? But it is based on only one box being checked and will uncheck the other boxes

// Check box 1 is checked

if (this.getField("checkbox1").value == "On") {

    // Uncheck box 2 & 3

    this.getField("checkbox2").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option1";

}

// Check box 2 is checked

else if (this.getField("checkbox2").value == "On") {

    // Uncheck box 1 & 3

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option2";

}

// Check box 3 is checked

else {

    // Uncheck box 1 & 2

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox2").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option3";

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

190

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I populate a text box based on the state of one of thee radio buttons?

Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

For example:

If radio button 1 = true textbox 1 = "option1"

If radio button 1 = false textbox 1 =""

If radio button 2 = true textbox 1 = "option2"

If radio button 2 = false textbox 1 =""

If radio button 3 = true textbox 1 = "option3"

If radio button 3 = false textbox 1 =""

all of the radio buttons = false the Textbox 1 should = ""

This might work....??? But it is based on only one box being checked and will uncheck the other boxes

// Check box 1 is checked

if (this.getField("checkbox1").value == "On") {

    // Uncheck box 2 & 3

    this.getField("checkbox2").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option1";

}

// Check box 2 is checked

else if (this.getField("checkbox2").value == "On") {

    // Uncheck box 1 & 3

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option2";

}

// Check box 3 is checked

else {

    // Uncheck box 1 & 2

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox2").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option3";

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

191

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 01, 2018 0
Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

Sorry, they are not radio buttons, they are check boxes

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Most Valuable Participant ,
Nov 01, 2018

Copy link to clipboard

Copied

What if more than one of the check-boxes is ticked?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 1
Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

if checkbox1 is true then the code needs to ignore checkbox2, and checkbox3, and texbox1 = "Opion1"

if checkbox2 is true and checkbox1 is false then the code needs to ignore checkbox1, and checkbox3, and textbox1 = "Option 2"

if checkbox3 is true and checkbox1 and checkbox 2 are  false then the code needs to ignore checkbox1, and checkbox2, and textbox1 = "Option 3"

It is an either or situation

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Most Valuable Participant ,
Nov 01, 2018

Copy link to clipboard

Copied

In that case you should give all the fields the same name but different export values, so they are mutually exclusive.

Then writing the code will be much easier, too...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 2
Engaged ,
Nov 01, 2018

Copy link to clipboard

Copied

This might work....??? But it is based on only one box being checked and will uncheck the other boxes

// Check box 1 is checked

if (this.getField("checkbox1").value == "On") {

    // Uncheck box 2 & 3

    this.getField("checkbox2").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option1";

}

// Check box 2 is checked

else if (this.getField("checkbox2").value == "On") {

    // Uncheck box 1 & 3

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox3").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option2";

}

// Check box 3 is checked

else {

    // Uncheck box 1 & 2

    this.getField("checkbox1").value = "Off";

    this.getField("checkbox2").value = "Off";

    // Set text field to Option...

    this.getField("textbox1").value = "Option3";

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 1
Most Valuable Participant ,
Nov 01, 2018

Copy link to clipboard

Copied

There's no need to reset the other fields if you simply give them all the same name, as I've explained.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 2
Community Beginner ,
Nov 02, 2018

Copy link to clipboard

Copied

This worked thanks, I modified I a little but it put me on the right track.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2018 1