I created a search form where the user has to insert the name of a city.
I associated the JS file to a JSON file containing the name of several cities. I want to display the whole list where a specific city has been included whenever the user types the name of it and clicks on the Search button.
I need a jQuery method to select which word has been written into the text field.
I used the CSS selector input[type=text]
here but I don't think it's the correct one:
$.ajax({
url: "http://localhost/prove/infoFrancigena_3.json",
dataType: "json",
success: function (data) {
console.log("getJSON wit AJAX method has been activated");
for (var i in data.tappe) {
//if (i.includes($("#inlineFormInputCittà"))) {
//if ($("#inlineFormInputCittà").val() === "Rome")
if (i.includes($(input[type=text]))) {
console.log("JSON file has been activated");
$("#tbody").append(i);
} else {
return false;
}
}
}
});
The JSON file is the following:
{
"tappe": [
{
"name": "Tappa22 - Passo della Cisa - Pontremoli",
"state": "Italy",
"region": "Toscana",
"city": "Groppoli(Mulazzo)"
},
{
"name": "Tappa22 - Passo della Cisa - Pontremoli",
"state": "Italy",
"region": "Toscana",
"city": "Groppodalosio"
}
]
}
How may I select the text inserted into a text field with jQuery?