• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dependent ComboBox to text field

Community Beginner ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Hi 

I have a dropdown(combobox) Field named Doctor, where upon selection, Phone and Address Field will auto populate. 

But when a user inputs that is not part of the dropdown list, the user can still write values on the Phone and Address Field. My code right now clears the phone and address field when user inputs value on the Doctor Field (dropdown, combobox) 

 

Another case is, when a user accidentally selects an item from the dropdown, but wanted to input value not on the list. I'd like to clear the phone and address field, then allow user to input another values. 

 

Thank You

if(event.value==""){
    this.getField("Phone").value="";
    this.getField("Address").value="";    
}

else if(event.value=="A"){
	this.getField("Phone").value = "PhoneA";
	this.getField("Address").value = "AddressA";
}

else if(event.value=="b"){
	this.getField("Phone").value = "PhoneC";
	this.getField("Address").value = "AddressC";
}

else{
    this.getField("Phone").value="";
    this.getField("Address").value=""
}

 

TOPICS
How to , JavaScript , PDF forms

Views

416

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 29, 2022 Aug 29, 2022

Move the code in the Doctor field as Custom Keystroke script.

 

You csn do something like :

 

if(event.willCommit && ( event.value !== "")) {

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

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

} else {

if (event.value == "A") {

this.getField("Phone").value ="Phone A";

this.getField("Address").value = "Address A";

}


if (event.value == "B") {

this.getField("Phone").value ="Phone C";

this.getField("Address").value ="Address C";

  }
}

Votes

Translate

Translate
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Use script as 'Validation'.

Votes

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
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Move the code in the Doctor field as Custom Keystroke script.

 

You csn do something like :

 

if(event.willCommit && ( event.value !== "")) {

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

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

} else {

if (event.value == "A") {

this.getField("Phone").value ="Phone A";

this.getField("Address").value = "Address A";

}


if (event.value == "B") {

this.getField("Phone").value ="Phone C";

this.getField("Address").value ="Address C";

  }
}

Votes

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
community guidelines
Community Beginner ,
Aug 30, 2022 Aug 30, 2022

Copy link to clipboard

Copied

Thanks. I didn't take about custom keystroke, this works well .

Votes

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
community guidelines
Community Beginner ,
Aug 30, 2022 Aug 30, 2022

Copy link to clipboard

Copied

LATEST

I modified the code a bit that works better for me. After checking that Doctor field is not empty, then it would check if event values are matching with any drop downs. If it doesn't match any drop downs, after commit it would erase the phone and address field. 

 

if(event.willCommit && ( event.value == "")) {

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

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

} else {

if (event.value == "A") {

this.getField("Phone").value ="Phone A";

this.getField("Address").value = "Address A";

}


else if (event.value == "B") {

this.getField("Phone").value ="Phone C";

this.getField("Address").value ="Address C";

  }

else if(event.willCommit && event.value !="") {
		this.getField("Phone").value ="";
		this.getField("Address").value ="";
	}

}

 

Votes

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
community guidelines