i Want To Display Only One line Masseges Into page












0















I Have Code For One Search Box and Search button, when I search item(this all are hidden) and Press Search It Will Display If Item Found And If Not Found Then It will Display Massage many time I Want to display it only once How Can I do ?






$('.contact-name').hide();
$('#search').click(function() {
$('.contact-name').hide();
var txt = $('#search-criteria').val();
$('.contact-name').each(function() {
if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
$(this).show();
} else {
document.write("Not Available");
}
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="search-criteria" />
<input type="button" id="search" value="search" />
<div class="contact-name">
<h3><a href="##">11023</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">IronMan</a></h3>
</div>
<div class="contact-name">
<h3><a href="##"> Avaialable </a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Thor</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Hulk</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Mr.Bean</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">X-man</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Fury</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Captain</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Hery</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Robot</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Batman</a></h3>
</div>
<div class="contact-name">
<h3><a href="##">Super man</a></h3>
</div>












share|improve this question





























    0















    I Have Code For One Search Box and Search button, when I search item(this all are hidden) and Press Search It Will Display If Item Found And If Not Found Then It will Display Massage many time I Want to display it only once How Can I do ?






    $('.contact-name').hide();
    $('#search').click(function() {
    $('.contact-name').hide();
    var txt = $('#search-criteria').val();
    $('.contact-name').each(function() {
    if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
    $(this).show();
    } else {
    document.write("Not Available");
    }
    });
    });

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="text" id="search-criteria" />
    <input type="button" id="search" value="search" />
    <div class="contact-name">
    <h3><a href="##">11023</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">IronMan</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##"> Avaialable </a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Thor</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Hulk</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Mr.Bean</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">X-man</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Fury</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Captain</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Hery</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Robot</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Batman</a></h3>
    </div>
    <div class="contact-name">
    <h3><a href="##">Super man</a></h3>
    </div>












    share|improve this question



























      0












      0








      0


      1






      I Have Code For One Search Box and Search button, when I search item(this all are hidden) and Press Search It Will Display If Item Found And If Not Found Then It will Display Massage many time I Want to display it only once How Can I do ?






      $('.contact-name').hide();
      $('#search').click(function() {
      $('.contact-name').hide();
      var txt = $('#search-criteria').val();
      $('.contact-name').each(function() {
      if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
      $(this).show();
      } else {
      document.write("Not Available");
      }
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <input type="text" id="search-criteria" />
      <input type="button" id="search" value="search" />
      <div class="contact-name">
      <h3><a href="##">11023</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">IronMan</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##"> Avaialable </a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Thor</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hulk</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Mr.Bean</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">X-man</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Fury</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Captain</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hery</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Robot</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Batman</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Super man</a></h3>
      </div>












      share|improve this question
















      I Have Code For One Search Box and Search button, when I search item(this all are hidden) and Press Search It Will Display If Item Found And If Not Found Then It will Display Massage many time I Want to display it only once How Can I do ?






      $('.contact-name').hide();
      $('#search').click(function() {
      $('.contact-name').hide();
      var txt = $('#search-criteria').val();
      $('.contact-name').each(function() {
      if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
      $(this).show();
      } else {
      document.write("Not Available");
      }
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <input type="text" id="search-criteria" />
      <input type="button" id="search" value="search" />
      <div class="contact-name">
      <h3><a href="##">11023</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">IronMan</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##"> Avaialable </a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Thor</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hulk</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Mr.Bean</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">X-man</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Fury</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Captain</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hery</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Robot</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Batman</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Super man</a></h3>
      </div>








      $('.contact-name').hide();
      $('#search').click(function() {
      $('.contact-name').hide();
      var txt = $('#search-criteria').val();
      $('.contact-name').each(function() {
      if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
      $(this).show();
      } else {
      document.write("Not Available");
      }
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <input type="text" id="search-criteria" />
      <input type="button" id="search" value="search" />
      <div class="contact-name">
      <h3><a href="##">11023</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">IronMan</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##"> Avaialable </a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Thor</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hulk</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Mr.Bean</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">X-man</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Fury</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Captain</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hery</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Robot</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Batman</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Super man</a></h3>
      </div>





      $('.contact-name').hide();
      $('#search').click(function() {
      $('.contact-name').hide();
      var txt = $('#search-criteria').val();
      $('.contact-name').each(function() {
      if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
      $(this).show();
      } else {
      document.write("Not Available");
      }
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <input type="text" id="search-criteria" />
      <input type="button" id="search" value="search" />
      <div class="contact-name">
      <h3><a href="##">11023</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">IronMan</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##"> Avaialable </a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Thor</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hulk</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Mr.Bean</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">X-man</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Fury</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Captain</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Hery</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Robot</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Batman</a></h3>
      </div>
      <div class="contact-name">
      <h3><a href="##">Super man</a></h3>
      </div>






      jquery html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 10:35









      Smollet777

      1,36011015




      1,36011015










      asked Nov 23 '18 at 8:14









      Sayra QueenSayra Queen

      14




      14
























          4 Answers
          4






          active

          oldest

          votes


















          1














          You can set flag value for displying message in proper way.



          Here is the solution you are searching for..Hope it will help you






          $('.contact-name').hide();
          $('#search').click(function() {
          var matchFound = false;
          $('.contact-name').hide();
          var txt = $('#search-criteria').val();
          $('.contact-name').each(function() {
          if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
          matchFound = true;
          $(this).show();
          }
          })
          if(!matchFound){
          document.write("Not Available");
          }
          });

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <input type="text" id="search-criteria" />
          <input type="button" id="search" value="search" />
          <div class="contact-name"><h3><a href="##">11023</a></h3></div>
          <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
          <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
          <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
          <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
          <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
          <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
          <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
          <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
          <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
          <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
          <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
          <div class="contact-name"><h3><a href="##">Super man</a></h3></div>








          share|improve this answer
























          • Thank You For Help This Is Work Thank A Lot Sir

            – Sayra Queen
            Nov 23 '18 at 11:14



















          0














          You can have a variable that indicates, whether the search item is found. After completing the search cycle, check the value of this variable and print the not-found message.



          var match = false;

          $('.contact-name').hide();
          var txt = $('#search-criteria').val();
          $('.contact-name').each(function() {
          if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
          $(this).show();
          match = true;
          }
          });

          if (!match) {
          document.write("Not Available");
          }





          share|improve this answer































            0














            One idea is first you can give 'id' to all your div tag and in your JS code just check the string input is same as id then remove the hidden tag from div.



            if ($('#idtagname').val() == txt)
            $('#idtagname').show()





            share|improve this answer


























            • @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

              – Mayank Jain
              Nov 23 '18 at 17:46





















            0














            Call a function that will show a div class that was hidden, and show it with the error.



            Check if div is already visible, if it is, then you don't need to apply any logic.



            Still since you are inside a each function, it will be triggered as many times as the elements of the class



            First place something like this:





            Then instead of using:



            document.write("Not Available");


            Do something like this:



            if($('.error').is(":hidden")){
            $('.error').show();
            $('.error').text("There isn't any div to show");
            }





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442845%2fi-want-to-display-only-one-line-masseges-into-page%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You can set flag value for displying message in proper way.



              Here is the solution you are searching for..Hope it will help you






              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>








              share|improve this answer
























              • Thank You For Help This Is Work Thank A Lot Sir

                – Sayra Queen
                Nov 23 '18 at 11:14
















              1














              You can set flag value for displying message in proper way.



              Here is the solution you are searching for..Hope it will help you






              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>








              share|improve this answer
























              • Thank You For Help This Is Work Thank A Lot Sir

                – Sayra Queen
                Nov 23 '18 at 11:14














              1












              1








              1







              You can set flag value for displying message in proper way.



              Here is the solution you are searching for..Hope it will help you






              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>








              share|improve this answer













              You can set flag value for displying message in proper way.



              Here is the solution you are searching for..Hope it will help you






              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>








              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>





              $('.contact-name').hide();
              $('#search').click(function() {
              var matchFound = false;
              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              matchFound = true;
              $(this).show();
              }
              })
              if(!matchFound){
              document.write("Not Available");
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <input type="text" id="search-criteria" />
              <input type="button" id="search" value="search" />
              <div class="contact-name"><h3><a href="##">11023</a></h3></div>
              <div class="contact-name"><h3><a href="##">IronMan</a></h3></div>
              <div class="contact-name"><h3><a href="##"> Avaialable </a></h3></div>
              <div class="contact-name"><h3><a href="##">Thor</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hulk</a></h3></div>
              <div class="contact-name"><h3><a href="##">Mr.Bean</a></h3></div>
              <div class="contact-name"><h3><a href="##">X-man</a></h3></div>
              <div class="contact-name"><h3><a href="##">Fury</a></h3></div>
              <div class="contact-name"><h3><a href="##">Captain</a></h3></div>
              <div class="contact-name"><h3><a href="##">Hery</a></h3></div>
              <div class="contact-name"><h3><a href="##">Robot</a></h3></div>
              <div class="contact-name"><h3><a href="##">Batman</a></h3></div>
              <div class="contact-name"><h3><a href="##">Super man</a></h3></div>






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 23 '18 at 9:19









              Darji SonaliDarji Sonali

              363




              363













              • Thank You For Help This Is Work Thank A Lot Sir

                – Sayra Queen
                Nov 23 '18 at 11:14



















              • Thank You For Help This Is Work Thank A Lot Sir

                – Sayra Queen
                Nov 23 '18 at 11:14

















              Thank You For Help This Is Work Thank A Lot Sir

              – Sayra Queen
              Nov 23 '18 at 11:14





              Thank You For Help This Is Work Thank A Lot Sir

              – Sayra Queen
              Nov 23 '18 at 11:14













              0














              You can have a variable that indicates, whether the search item is found. After completing the search cycle, check the value of this variable and print the not-found message.



              var match = false;

              $('.contact-name').hide();
              var txt = $('#search-criteria').val();
              $('.contact-name').each(function() {
              if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
              $(this).show();
              match = true;
              }
              });

              if (!match) {
              document.write("Not Available");
              }





              share|improve this answer




























                0














                You can have a variable that indicates, whether the search item is found. After completing the search cycle, check the value of this variable and print the not-found message.



                var match = false;

                $('.contact-name').hide();
                var txt = $('#search-criteria').val();
                $('.contact-name').each(function() {
                if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
                $(this).show();
                match = true;
                }
                });

                if (!match) {
                document.write("Not Available");
                }





                share|improve this answer


























                  0












                  0








                  0







                  You can have a variable that indicates, whether the search item is found. After completing the search cycle, check the value of this variable and print the not-found message.



                  var match = false;

                  $('.contact-name').hide();
                  var txt = $('#search-criteria').val();
                  $('.contact-name').each(function() {
                  if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
                  $(this).show();
                  match = true;
                  }
                  });

                  if (!match) {
                  document.write("Not Available");
                  }





                  share|improve this answer













                  You can have a variable that indicates, whether the search item is found. After completing the search cycle, check the value of this variable and print the not-found message.



                  var match = false;

                  $('.contact-name').hide();
                  var txt = $('#search-criteria').val();
                  $('.contact-name').each(function() {
                  if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
                  $(this).show();
                  match = true;
                  }
                  });

                  if (!match) {
                  document.write("Not Available");
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 8:18









                  Martin HeraleckýMartin Heralecký

                  3,11721034




                  3,11721034























                      0














                      One idea is first you can give 'id' to all your div tag and in your JS code just check the string input is same as id then remove the hidden tag from div.



                      if ($('#idtagname').val() == txt)
                      $('#idtagname').show()





                      share|improve this answer


























                      • @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                        – Mayank Jain
                        Nov 23 '18 at 17:46


















                      0














                      One idea is first you can give 'id' to all your div tag and in your JS code just check the string input is same as id then remove the hidden tag from div.



                      if ($('#idtagname').val() == txt)
                      $('#idtagname').show()





                      share|improve this answer


























                      • @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                        – Mayank Jain
                        Nov 23 '18 at 17:46
















                      0












                      0








                      0







                      One idea is first you can give 'id' to all your div tag and in your JS code just check the string input is same as id then remove the hidden tag from div.



                      if ($('#idtagname').val() == txt)
                      $('#idtagname').show()





                      share|improve this answer















                      One idea is first you can give 'id' to all your div tag and in your JS code just check the string input is same as id then remove the hidden tag from div.



                      if ($('#idtagname').val() == txt)
                      $('#idtagname').show()






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 23 '18 at 8:30









                      dwjohnston

                      2,796114890




                      2,796114890










                      answered Nov 23 '18 at 8:25









                      Mayank JainMayank Jain

                      665




                      665













                      • @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                        – Mayank Jain
                        Nov 23 '18 at 17:46





















                      • @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                        – Mayank Jain
                        Nov 23 '18 at 17:46



















                      @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                      – Mayank Jain
                      Nov 23 '18 at 17:46







                      @dwjohnston , It was such a big mistake made from my part that you have to take time to correct it. i really appreciate you man. if you were not there then no one in this world would have ever understand it.

                      – Mayank Jain
                      Nov 23 '18 at 17:46













                      0














                      Call a function that will show a div class that was hidden, and show it with the error.



                      Check if div is already visible, if it is, then you don't need to apply any logic.



                      Still since you are inside a each function, it will be triggered as many times as the elements of the class



                      First place something like this:





                      Then instead of using:



                      document.write("Not Available");


                      Do something like this:



                      if($('.error').is(":hidden")){
                      $('.error').show();
                      $('.error').text("There isn't any div to show");
                      }





                      share|improve this answer




























                        0














                        Call a function that will show a div class that was hidden, and show it with the error.



                        Check if div is already visible, if it is, then you don't need to apply any logic.



                        Still since you are inside a each function, it will be triggered as many times as the elements of the class



                        First place something like this:





                        Then instead of using:



                        document.write("Not Available");


                        Do something like this:



                        if($('.error').is(":hidden")){
                        $('.error').show();
                        $('.error').text("There isn't any div to show");
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          Call a function that will show a div class that was hidden, and show it with the error.



                          Check if div is already visible, if it is, then you don't need to apply any logic.



                          Still since you are inside a each function, it will be triggered as many times as the elements of the class



                          First place something like this:





                          Then instead of using:



                          document.write("Not Available");


                          Do something like this:



                          if($('.error').is(":hidden")){
                          $('.error').show();
                          $('.error').text("There isn't any div to show");
                          }





                          share|improve this answer













                          Call a function that will show a div class that was hidden, and show it with the error.



                          Check if div is already visible, if it is, then you don't need to apply any logic.



                          Still since you are inside a each function, it will be triggered as many times as the elements of the class



                          First place something like this:





                          Then instead of using:



                          document.write("Not Available");


                          Do something like this:



                          if($('.error').is(":hidden")){
                          $('.error').show();
                          $('.error').text("There isn't any div to show");
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 23 '18 at 9:16









                          TiagoMTiagoM

                          1,51042560




                          1,51042560






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442845%2fi-want-to-display-only-one-line-masseges-into-page%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Wiesbaden

                              Marschland

                              Dieringhausen