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

Javascript to make fields hidden or visible based on drop-down selection

New Here ,
Jun 13, 2024 Jun 13, 2024

I have a drop-down box asking is a "Shipping Address is the same as above". If they select "No" then text fields to have them enter the Address/City/St/Zip should be made visible. If they answer "Yes", that the Shipping Address is the same, then the Addess/City/St/Zip fields should be made to be hidden. Below is the code that I have, which isn't working, as selecting "No" does not hide any fields. The default selection for the field just displays "Please select", so the user knows they need to select something in that text box. I have the below Javascript set to run from the Actions tab on Mouse Up, in the Yes/No drop down box asking if the Shipping Address is the same as above.

 

if(this.getField("274 Shipping Addr Same?").value=="Yes"){
this.getField("274 Shipping FI Name").display = display.hidden;
this.getField("274 FI Attention Contact Form").display = display.hidden;
this.getField("274 Shipping Addr1").display = display.hidden;
this.getField("274 Shipping Addr2").display = display.hidden;
this.getField("274 Shipping FI City").display = display.hidden;
this.getField("274 FI Shipping State").display = display.hidden;
this.getFielNo("274 Shipping Zip").display = display.hidden;
}else{
if(this.getField("274 Shipping Addr Same?").value=="No"){
this.getField("274 Shipping FI Name").display = display.visible;
this.getField("274 FI Attention Contact Form").display = display.visible;
this.getField("274 Shipping Addr1").display = display.visible;
this.getField("274 Shipping Addr2").display = display.visible;
this.getField("274 Shipping FI City").display = display.visible;
this.getField("274 FI Shipping State").display = display.visible;
this.getField("274 Shipping Zip").display = display.visible;
}else{
this.getField("274 Shipping FI Name").display = display.hidden;
this.getField("274 FI Attention Contact Form").display = display.hidden;
this.getField("274 Shipping Addr1").display = display.hidden;
this.getField("274 Shipping Addr2").display = display.hidden;
this.getField("274 Shipping FI City").display = display.hidden;
this.getField("274 FI Shipping State").display = display.hidden;
this.getField("274 Shipping Zip").display = display.hidden;
}
}

 

 

TOPICS
JavaScript
460
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 13, 2024 Jun 13, 2024

Remove that code and place this one under the custom Validation event of the drop-down, and make sure to tick the option to commit the selected value immediately, under the field's Options tab in the Properties dialog, too:

 

 

if (event.value == "No") {
	this.getField("274 Shipping FI Name").display = display.visible;
	this.getField("274 FI Attention Contact Form").display = display.visible;
	this.getField("274 Shipping Addr1").display = display.visible;
	this.getField("274 Shipping Addr2").display = display.visible;
	this.getField("274 Shipping FI City").display = display.visible;
	this.getField("274 FI Shipping State").display = display.visible;
	this.getField("274 Shipping Zip").display = display.visible;
} else {
    this.getField("274 Shipping FI Name").display = display.hidden;
    this.getField("274 FI Attention Contact Form").display = display.hidden;
    this.getField("274 Shipping Addr1").display = display.hidden;
    this.getField("274 Shipping Addr2").display = display.hidden;
    this.getField("274 Shipping FI City").display = display.hidden;
    this.getField("274 FI Shipping State").display = display.hidden;
    this.getField("274 Shipping Zip").display = display.hidden;
}

 

 

If it still doesn't work check the JS Console for errors.

 

Edited: Fixed a mistake in the code

 

View solution in original post

Translate
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 ,
Jun 13, 2024 Jun 13, 2024

Remove that code and place this one under the custom Validation event of the drop-down, and make sure to tick the option to commit the selected value immediately, under the field's Options tab in the Properties dialog, too:

 

 

if (event.value == "No") {
	this.getField("274 Shipping FI Name").display = display.visible;
	this.getField("274 FI Attention Contact Form").display = display.visible;
	this.getField("274 Shipping Addr1").display = display.visible;
	this.getField("274 Shipping Addr2").display = display.visible;
	this.getField("274 Shipping FI City").display = display.visible;
	this.getField("274 FI Shipping State").display = display.visible;
	this.getField("274 Shipping Zip").display = display.visible;
} else {
    this.getField("274 Shipping FI Name").display = display.hidden;
    this.getField("274 FI Attention Contact Form").display = display.hidden;
    this.getField("274 Shipping Addr1").display = display.hidden;
    this.getField("274 Shipping Addr2").display = display.hidden;
    this.getField("274 Shipping FI City").display = display.hidden;
    this.getField("274 FI Shipping State").display = display.hidden;
    this.getField("274 Shipping Zip").display = display.hidden;
}

 

 

If it still doesn't work check the JS Console for errors.

 

Edited: Fixed a mistake in the code

 

Translate
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
New Here ,
Jun 13, 2024 Jun 13, 2024
LATEST

That worked. Thanks!!!!!

Translate
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