Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:00:22+00:00 2026-05-30T08:00:22+00:00

I have the following JSON and Jquery Code: JSON { employees:[ { name: Sandy

  • 0

I have the following JSON and Jquery Code:

JSON

{
    "employees":[
        {
            "name": "Sandy"
        },
        {
            "name": "Megan"
        },  
        {
            "name": "Pat"
        },
        {
            "name": "Susan"
        }
    ]
}

JQuery

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="js/jquery-1.6.4.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                jQuery.ajax({
                    type: "GET",
                    url: "myJson.json",
                    dataType: "json",
                    async: "true",
                    contentType: "application/x-javascript; charset=utf-8",
                    cache: "false",
                    success: function(response){
                        $("input#myInput").live("keyup", function(e){

                            var val = $("input#myInput").val();
                            var len = $("input#myInput").val().length;

                            for (var x = 0; x < response.employees.length; x++) {

                                var empName = response.employees[x].name;
                                var valChar = val.substring(0, len);
                                var nameChar = empName.substring(0, len);

                                if (nameChar.search(valChar) != -1) {
                                    $("ul#myList").append("<li>" + empName + "</li>");
                                }                               
                            }
                        });
                    }
                })
            })
        </script>
    </head>
    <body>
        <input type="text" width="25" id="myInput">
        <ul id="myList"></ul>
    </body>
</html>

What I want to do

When I type a character in the input field such as M/P/S, it should loop through the JSON file and return matching results. So,

  • M will return Megan
  • S will return Sandy and Susan
  • P will return Pat

Problem

Currently, my code is working. BUT only when I input the characters in upper case. If I type in m/p/s, it does not return anything.

How can I make this case-insensitive so that it works for both

  • M/P/S
  • m/p/s
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:00:23+00:00Added an answer on May 30, 2026 at 8:00 am

    Edit: Some improvements in your code

    1. val and val.substring(0,len) is same so you don’t need to do do substring as len is calculated from val.
    2. You don’t need to do search as you use substring and get the exact length of val.. so you can do a simple == comparision

         for (var x = 0; x < resp.employees.length; x++) {
      
              var empName = resp.employees[x].name;
              var valChar = val.toLowerCase();
              var nameChar = empName.substring(0, len).toLowerCase();
      
              if (nameChar === valChar) {
                  $("ul#myList").append("<li>" + empName + "</li>");
              }                               
          }
      

    Updated DEMO

    Change your for loop as below,

            for (var x = 0; x < resp.employees.length; x++) {
    
                var empName = resp.employees[x].name;
                var valChar = val.substring(0, len).toLowerCase();
                var nameChar = empName.substring(0, len).toLowerCase();
    
                if (nameChar.search(valChar) != -1) {
                    $("ul#myList").append("<li>" + empName + "</li>");
                }                               
            }
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following 2 files as below: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
I have follwing JSON: {mykey:[{name:Jak,interests:movies}]} and following opensocial app code: <script type=text/os-template require=mykey> <ul>
I have the following JQUERY code that I'm expecting to return 3 json results
I have the following code to convert my JSON dataset to html table. I
I have the following json code file named: sections.json { section1: { priority: 1,
I have an json output of the following (ignore the escape characters) {\sEcho\:1,\iTotalRecords\:10,\iTotalDisplayRecords\:10,\aaData\:[{\Job\:\developer\,\Name\:\kurt\},{\Job\:\plumber\,\Name\:\john\}]} which
I have the following json array of objects in my code var groups =
I have the following code jQuery.getJSON(encodeURI(strUrl), {address:address,state:state, zip:zip},function(data){ alert('HELLO World!'); }); If for some
I have the following jquery in my code $j.getJSON(http://localhost:8080/WWTestHarnessWEB/ReadersToolkitFinalController.htm?jsoncallback=?, {'uID': 1}, function(data){alert(data);}); The json
I have my front end script which has the following jQuery code: $.get(/backend/post.php, {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.