简体   繁体   中英

How to make an input not case sensitive

I want to know how make it when the user types in something to an input it doesn't have to be the same capitalization as the value for the document.getElementById("spanId").innerHTML = "146.5 meters"; to appear.

HTML

<input id="ask" type="text"
       placeholder = "Ex: how tall is the Gateway Arch"
       onfocus="this.placeholder = ''"
       onblur="this.placeholder = 'Ex: how tall is the gateway arch'"
       text-align: center/>

JS

document.getElementById("button").onclick = function() {
    if (document.getElementById("ask").innerHTML == "how tall are the pyramids") {
        document.getElementById("spanId").innerHTML = "146.5 meters";
    } else if (document.getElementById("ask").value == "how tall is the gateway arch") {
        document.getElementById("spanId").innerHTML = "630 feet";
    } else if (document.getElementById("ask").value == "how tall is the empire state building") {
        document.getElementById("spanId").innerHTML = "1,454 feet";
    }
}

First , use value instead of innerHTML for input fields

Second , convert both side lowercase or uppercase during comparing

Try like this

var ask=document.getElementById("ask").value.toLowerCase();
if (ask =="how tall are the pyramids")

Or like this

var ask=document.getElementById("ask").value.toUpperCase();
if (ask =="how tall are the pyramids".toUpperCase())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM