What I have:

enter image description here

<input name="dcity" placeholder="from" id="from" type="text" onkeyup="showHint(this.value)" > <input name="acity" placeholder="to" id="to" type="text" onkeyup="showHint(this.value)" > <p>Suggestions: <span id="txtHint"></span></p> function showHint(str) { if (str.length == 0) { document.getElementById("txtHint").innerHTML = ""; return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET", "gethint.php?q=" + str, true); xmlhttp.send(); } 

I enter the first letters of the city and gives me a hint

 $a[] = "Tbilisi"; $a[] = "Rome"; $q = $_REQUEST["q"]; $hint = ""; if ($q !== "") { $q = strtolower($q); $len=strlen($q); foreach($a as $city) { if (stristr($q, substr($city, 0, $len))) { if ($hint === "") { $hint = $city; } else { $hint .= ", $city"; } } } } echo $hint === "" ? "no suggestion" : $hint; 

This is what I want and I don’t know how to

enter image description here

I will forgive the help, it is very necessary!

  • Greetings. Now, after all, displays a hint around the city? If so, what should be done? - Maxim Bogdanov
  • As I understand it, he wants it to be a drop-down list and not a separate line - pnp2000

1 answer 1

Good day, if I understand you correctly, it is called autocomplete. Here is the jQuery solution

  • Thank you very much for your help) - Oblivion