Copy link to clipboard
Copied
Can someone help me on how to made text fields visible/hidden based on the value of another text field?
I have 3 text fields; Field1, Field2 and Field3.
I want to set up my form so that if the value of Field1 is less than 10, Field2 will be hidden and Field3 will be visible for people to enter a value in that field. If Field1 is 10 or more, Field3 should be hidden and Field2 should be visible and on focus.
It seems like I need a custom validation code for Field1 but I have no clue how to code.
Use this code as the custom validation script of Field1:
var f2 = this.getField("Field2");
var f3 = this.getField("Field3");
if (event.value=="") {
f2.display = display.hidden;
f3.display = display.hidden;
f2.value = "";
f3.value = "";
} else if (Number(event.value)<10) {
f2.display = display.hidden;
f3.display = display.visible;
f2.value = "";
} else {
f2.display = display.visible;
f3.display = display.hidden;
f3.value = "";
}
Copy link to clipboard
Copied
What about if Field1 is empty? Should then both the fields be hidden?
Copy link to clipboard
Copied
Actually I want to make Field1 a "required" field so that it will never be empty.
Copy link to clipboard
Copied
It will be empty until filled in unless you are providing a default value.
Copy link to clipboard
Copied
The two things are not related to each other. A required field can be empty.
Copy link to clipboard
Copied
Oh I see. If that's the case, I'd like for both to be hidden if Field1 is empty
Copy link to clipboard
Copied
Use this code as the custom validation script of Field1:
var f2 = this.getField("Field2");
var f3 = this.getField("Field3");
if (event.value=="") {
f2.display = display.hidden;
f3.display = display.hidden;
f2.value = "";
f3.value = "";
} else if (Number(event.value)<10) {
f2.display = display.hidden;
f3.display = display.visible;
f2.value = "";
} else {
f2.display = display.visible;
f3.display = display.hidden;
f3.value = "";
}
Copy link to clipboard
Copied
This worked perfectly. Thank you!!!!
Copy link to clipboard
Copied
I have similar case.
I have two fields. First is a text field and other dropdown.
I want to display/show dropdown only when I enter text in field 1.
Copy link to clipboard
Copied
You can use I provided above to do that.
Copy link to clipboard
Copied
I do not have the number value. It is the name field. When a person writes 3 characters second field should be displayed.
Copy link to clipboard
Copied
So it is 3 characters, or any value at all?
The basic code is the same:
var f2 = this.getField("Field2");
if (event.value=="") {
f2.display = display.hidden;
} else {
f2.display = display.visible;
}