search in a json file and return the value in the html tag

Thanks for @Swati for help me to find the solution. By the following change in JS file the result appears:

$(document).ready(function(){
    $.ajaxSetup({ cache: false });
    $('#search').keyup(function(){
     $('#result').html('');
     $('#state').val('');
     var searchField = $('#search').val();
     var expression = new RegExp(searchField, "i");
     $.getJSON('json/db.json', function(data) {
      $.each(data, function(key, value){
       if (value.InstrumentID.search(expression) != -1 || value.LVal18.search(expression) != -1 || value.LVal18AFC.search(expression) != -1 || value.LVal30.search(expression) != -1 || value.CompanyLVal18AFC.search(expression) != -1 || value.CompanyLVal30.search(expression) != -1) 
       {
    $('#result').append('<li class="list-group-item link-class"> '+value.LVal30+' | <span class="text-muted">'+value.LVal18AFC+'</span> | <span style="display: none !important">'+value.InstrumentID+'</span></li>');
       }
      });   
     });
    });
    
    $('#result').on('click', 'li', function() {

     var click_text = $(this).text().split('|');
     $('#search').val($.trim(click_text[0]));
     $("#result").html('');
    });

    
    $("#getValue").click(function(){
    if($('#search').val() != null && $('#search').val() != "" )
    {
        $("d").text($('#search').val().split(',')[0]);
        $("d1").text($('#search').val().split(',')[1]);
        $("d2").text($('#search').val().split(',')[2]);
    }else{
    $("d").text(" ");
    }
    });
});

and also defining d, d1, d2 tags in my HTML file. I would be able to show the search result in several tags. Thanks again @Swati

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top