Answer the question
In order to leave comments, you need to log in
Framework Yii2. Is it possible to set value in ActiveForm using div?
Dear programmers, I am writing to you with this question
. Is it possible to specify the value in the ActiveForm field->textInput form in Value?
Here's the thing: I connected JavaScript Yandex Api maps and a geocoder, wrote a simple documentary code so that the user can select a specific house or street on the map, and now I need to somehow extract this data from JS and place it in the form for sending
Here is the script code launching YandexMaps
<script type="text/javascript">
ymaps.ready(init);
function init() {
var myPlacemark,
myMap = new ymaps.Map('map', {
center: [55.753994, 37.622093],
zoom: 9
}, {
searchControlProvider: 'yandex#search'
});
myMap.events.add('click', function (e) {
var coords = e.get('coords');
if (myPlacemark) {
myPlacemark.geometry.setCoordinates(coords);
}
else {
myPlacemark = createPlacemark(coords);
myMap.geoObjects.add(myPlacemark);
myPlacemark.events.add('dragend', function () {
getAddress(myPlacemark.geometry.getCoordinates());
});
}
getAddress(coords);
});
function createPlacemark(coords) {
return new ymaps.Placemark(coords, {
iconCaption: 'поиск...'
}, {
preset: 'islands#violetDotIconWithCaption',
draggable: true
});
}
function getAddress(coords) {
myPlacemark.properties.set('iconCaption', 'поиск...');
ymaps.geocode(coords).then(function (res) {
var firstGeoObject = res.geoObjects.get(0);
myPlacemark.properties
.set({
iconCaption: [
firstGeoObject.getLocalities().length ? firstGeoObject.getLocalities() : firstGeoObject.getAdministrativeAreas(),
firstGeoObject.getThoroughfare() || firstGeoObject.getPremise()
].filter(Boolean).join(', '),
balloonContent: firstGeoObject.getAddressLine()
});
var adress = firstGeoObject.getAddressLine();
document.getElementById("adress").innerHTML = adress;
});
}
}
</script>
Answer the question
In order to leave comments, you need to log in
1. Assign a class to the desired input
2. Помещаете данные
Это с помощью jquery, если на чистом JS, то можно присвоить так же id и по нему работать
let address = document.getElementById('address');
address.value = 'my address';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question