Q:

Visibility of textfield based on other value

HI I am new to JavaScript any help or suggestion will be really much appreciated. 
I want my two textfield will be visible. 
My code below is working for single only without semicolon but the variable sometimes with semicolon if multiple I am just wondering if its possible I will really appreciate advice. 
var comp = "apple";

$( document ).ready(function() {
   var comp = "apple";
   $('#txt1').hide();
   $('#txt2').hide();
   $('#txt3').hide();
   if (comp == "apple"){
     $('#txt1').show();
   }

});   

but if
 var comp = "apple;ice;grapes"; 

As apple and grapes is in the variable, apple and grapes should be visible. 

A:

== returns true if the operands are equal.  And obviously, "apple;ice;grapes" ! = "apple". 
You can use String.prototype.includes():

The includes() method determines whether one string may be found within another string, returning true or false as appropriate. 

Please Note: You can pass multiple id as part of the selector to hide() them.  But it is better to use CSS to set the style when possible. 

$( document ).ready(function() {
  var comp = "apple;ice;grapes"; 
  //$('#txt1,#txt2,#txt3').hide();
  if (comp.includes("apple") && comp.includes("grapes")){
    $('#txt1, #txt2').show();
  }
});
#txt1,#txt2,#txt3{
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="txt1">apple</div>
<div id="txt2">grapes</div>
<div id="txt3">ice</div>

