I have a block on my site to check connectivity https://internet-kz.info/ There is a list of all cities, streets, and house numbers that are connected to Beeline in Kazakhstan! How to make that when entering the name of the city a list of what is there falls out! What would appear only streets and houses of Almaty in Almaty! And not a complete file of 30,000 houses, how much is it worth if you order from a freelancer ?? If there is an example and html code that my programmer could do! If it's not difficult there. Thank you in advance for your reply.
Closed due to the fact that off-topic participants 0xdb , Air , Enikeyschik , AR Hovsepyan , yolosora 28 Dec '18 at 5:55 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, yolosora
|
1 answer
That's how it is solved on the knee. You can write a value in <input> and it will display hints or select it directly from the hint. As you fill out the form itself will pick up the streets and their homes.
let data = [{ city: "Алматы", data: [{ street: "Абая", houses: [1, 34, 65, 87] }, { street: "Сатпаева", houses: [2, 4, 5, 7] }, ] }, { city: "Есик", data: [{ street: "Спортивная", houses: [33, 3, 5, 7] }, { street: "Сатпаева", houses: [25, 43, 54, 75] }, ] }, { city: "Шымкент", data: [{ street: "Какой-то город", houses: [343, 35, 52, 7] }, { street: "Еще один город", houses: [245, 43, 54, 75] }, ] } ]; let path = { city: null, street: null, house: null } $("body").append("<datalist id='citys'>" + data.map(item => "<option>" + item.city + "</option>").join("") + "</datalist>"); $("input[name='city']").on("change", (e) => { $("datalist[id='streets']").remove(); $("datalist[id='houses']").remove(); $("input[name='street']").val(""); $("input[name='house']").val(""); let elem = $(e.currentTarget); if (elem.val()) { let cityIndex = data.findIndex(item => item.city === elem.val()); path.city = cityIndex; $("body").append("<datalist id='streets'>" + data[cityIndex].data.map(item => "<option>" + item.street + "</option>").join("") + "</datalist>"); } }); $("input[name='street']").on("change", (e) => { $("datalist[id='houses']").remove(); $("input[name='house']").val(""); let elem = $(e.currentTarget); if (elem.val()) { let streetIndex = data[path.city].data.findIndex(item => item.street === elem.val()); path.street = streetIndex; $("body").append("<datalist id='houses'>" + data[path.city].data[streetIndex].houses.map(item => "<option>" + item + "</option>").join("") + "</datalist>"); } }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form> <input name="city" id="city" list="citys"> <input name="street" id="street" list="streets"> <input name="house" id="house" list="houses"> </form> - Thank you very much! How do I accomplish your goal! Tomorrow I will ask a programmer - Anatoly Burenko
- Are you from Kazakhstan :) ?? - Anatoly Burenko
- @ Anatoly Burenko yes, from Almaty) - Misha Saidov
- Thank you very much again! Really really helped! Thanks, on this site you can search for specialists who will do the work for the money ??? - Anatoly Burenko
|