As a disclaimer, I'd like to apologize for an issue that has inevitably been discussed time and time again. Please, honestly, please forgive me.
I'm -trying to- create a request form. The end user can request up to five documents on this form. Each of these potentially 5 documents have a text box for the document number (Doc2...5 - one being default) and a combo box for them to select the corresponding product line (Prod2...5). The people here aren't that bright (and I fit right in, apparently), so I wanted to create a field that requires them to enter the number of documents - a radio button field or combo box. Once they've selected the number of documents they'll be requesting, the appropriate number of fields will be visible. (example: 3 products would change the visibility of Doc2, Prod2 & Doc3, Prod3)
So I've written this 25 buzzillion different ways over the span of a week and a half, and none of them seem to be right. I've got the extra fields set to invisible by default. I've been trying to use export values (which I think is right?) to determine the field values in order to change visibility of the fields. Given a person is filling out the form, they're going to be requesting at least 1 document, so I really don't need to address that field, or at least set any actions for it... (I don't think?)
Here is my latest attempt. (NumDoc = number of documents - i.e. the part that's driving me crazy)
}
var Nd = this.getField("NumDoc").value {
if(Nd==2);{
(this.getField("Doc2").display = display.visible;
this.getField("Doc3").display = display.hidden;
this.getField("Doc4").display = display.hidden;
this.getField("Doc5").display = display.hidden;
this.getField("Prod2").display = display.visible;
this.getField("Prod3").display = display.hidden;
this.getField("Prod4").display = display.hidden;
this.getField("Prod5").display = display.hidden;)
}
else;{
if(Nd==3);{
...etc
I know this is a really ridiculous way of doing it, but honestly, I don't know what else to do. I was originally working with radio buttons, all same name, all separate export values, and I did get the fields to display when the corresponding button was selected, but they STAYED visible - even when a different selection was made.
If any of you could find it in your heart to help a newb, my sanity and I would greatly appreciate it!
Thanks
Bianca
Let me trade you a switch statement for that If ... else tree you've got there. I can only see 20% of it and it's giving me a headache; I can't imagine what it's doing to you :)
I don't see where this should fail on its own; I've used display to successfully show/hide fields. As an isolated method it looks ok. If I had to guess what was causing a problem all I've got left is the Nd variable. Is it coming in as a string? To make sure that you're getting a number and not a string from that field:
var Nd = parseInt(this.getField("NumDoc").value )
Not sure if parseInt() is necessary, but it will eliminate my first suspicion that Nd may be NaNing up your efforts.
(Edit: In my test parseInt() was not necessary, switch (getField("NumDoc").value) worked as intended)
(Edit 2: parseInt() would also help if you've got non-numbers in the NumDoc field. Letters, spaces, etc.)