K
K
kursof2017-08-01 14:33:11
JavaScript
kursof, 2017-08-01 14:33:11

How to implement when issuing js one issue another?

Is there a ready-made code
https://jsfiddle.net/tty37u7m/
that gives you the location of your city?
it gives out like this

<p>Страна: <span id="country"></span></p>
<p>Край(обл.): <span id="state"></span></p>
<p>Город: <span id="city"></span></p>
<p>Адрес: <span id="address"></span></p>
<p>Широта: <span id="latitude"></span></p>
<p>Долгота: <span id="longitude"></span></p>

on the issuance of course everything is clear!
so that's the crux of the matter!
let's say my city is "North"
someone else's city for example "South"
is it possible to somehow attach to the html code else if And the like
well, that is, if my
City is: "North"
then it gives information "33"
and if
City: "SOUTH"
then "11" is an
example code
if ($city == 'Казань') {
    echo 'Наш телефон для Казани 1111111';
} elseif ($city == 'Москва') {
    echo 'Телефон для Москвы 2222222';
} elseif ($city == 'Санкт-Петербург') {
    echo 'Телефон для Санкт-Петербурга 3333333';
} elseif ($city == 'Тюмень') {
    echo 'Телефон для Тюмени 4444444';
} else {
    echo 'Ваш город ' . $city . '.';

may seem like a mess, I apologize for the bad wording of the explanation!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2017-08-01
@kursof

You can add a field and a function

$.getJSON(GEOCODING).done(function(location) {
    $('#country').html(location.results[0].address_components[5].long_name);
    $('#state').html(location.results[0].address_components[4].long_name);
    $('#city').html(location.results[0].address_components[2].long_name);
    $('#address').html(location.results[0].formatted_address);
    $('#latitude').html(position.coords.latitude);
    $('#longitude').html(position.coords.longitude);
    getPhone(location.results[0].address_components[2].long_name);
  })

and describe this function like this
function getPhone(city){
$.('#phonenumber').innerHTML = (city=='Казань'? '1111111111':city='Москва'?'2222222222':'...';
}

Or if you have numbers in each city stored in the database - then make an AJAX request to the script on the server passing the name of the city in the parameters and already on the server in the database find the number corresponding to the received city.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question