title: Adobe PDF JavaScript for Forms: showing & hiding labels depending on the conditions
body: <p>I am designing forms in PDF and validating user input using JavaScript, however it does not seems to work as planed. Please see my sample code below.</p>
  
  <pre><code>var selection1 = this.getField("textfield1").value;
  var selection2= this.getField("textfield2").value;
  
  if (selection1 == "Please select" &amp;&amp; selection2 == "Please select")
  {
      getField("Label1").display=display.hidden;
      getField("Label2").display=display.hidden;
      getField("Label3").display=display.hidden;
  }
  else if (selection1 == "Please select" &amp;&amp; selection2 == "oranges")
  {
      getField("Label1").display=display.hidden;
      getField("Label2").display=display.hidden;
      getField("Label3").display=display.hidden;
  }
  else if ((selection2 == "oranges") &amp;&amp; (selection1 == "two" || "four" || "six" || "eight”) )
  {
      getField("Label1").display=display.hidden;
      getField("Label2").display=display.visible;
      getField("Label3").display=display.visible;
  }
  else if ((selection2 == "oranges") &amp;&amp; (selection1 == "three" || "five" || "seven" || "nine") )
  {
      getField("Label1").display=display.visible;       
      getField("Label2").display=display.hidden;
      getField("Label3").display=display.hidden;
  }
  </code></pre>
  
  <p>As you can see from above code, certain labels become hidden and visible depending on the user selection from the multiple drop-down lists.</p>
  
  <p>My 1st issue, in the part of the code <code>selection1 ==</code> which has multiple <code>||</code> only first condition works i.e. <code>"two"</code> and everything else is ignored, if users selects <code>"four"</code> for example, nothing happens.</p>
  
  <p>My 2nd issue, when user selects the following combination <code>selection1 = "Please select" &amp; selection2 = "oranges"</code> it displays <code>Label1</code> for some reason.</p>
  
  <p>My 3rd issue, if for example user selected <code>selection2 = "oranges" &amp; selection1 = "three"</code> it displays <code>Label1</code> correctly, however if user changes selection to lets say, <code>selection1 = "two"</code>, for some reason <code>Label1</code> is still visible and <code>Label2 &amp; Label3</code> are still hidden.</p>
  
  <p>The above code has been pasted into the Calculation (Printscreen 1) section of the hidden textbox, I have also tried pasting it to Validation section of the drop-down list (Printscreen 2) itself, however nothing seems to be working. I have also tried to use <strong>Switch Statement</strong> but because my <code>selection1</code> has multiple conditions it also does not seems to work. Please also note my <code>selection1</code> has in the region of 40 <code>||</code> conditions, and overall I have in the region of 25-30 different scenarios. </p>
  
  <p><em>Your help would be greatly appreciated, thank you in advance.</em></p>
  
  <p>Printscreen 1</p>
  
  <p><a href="https://i.stack.imgur.com/Ce12Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ce12Y.png" alt="enter image description here"></a></p>
  
  <p>Printscreen 2</p>
  
  <p><a href="https://i.stack.imgur.com/7M4co.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7M4co.png" alt="enter image description here"></a></p>