Answer the question
In order to leave comments, you need to log in
How to pass a variable from JavaScript to ActiveForm in YII2?
The code ends with a function like this and code
function savecoordinats (){
var new_coords = [coords[0].toFixed(4), coords[1].toFixed(4)];
myPlacemark.getOverlaySync().getData().geometry.setCoordinates(new_coords);
document.getElementById("latlongmet").value = new_coords;
document.getElementById("mapzoom").value = myMap.getZoom();
var center = myMap.getCenter();
var new_center = [center[0].toFixed(4), center[1].toFixed(4)];
document.getElementById("latlongcenter").value = new_center;
}
<div id="map"></div>
<div id="coord_form">
<p><label>Координаты метки: </label><input id="latlongmet" class="form-control" name="icon_text" /><br/>
<label>Масштаб: </label><input id="mapzoom" class="form-control" name="icon_text" /></p>
<p><label>Центр карты: </label><input id="latlongcenter" class="form-control" name="icon_text" /></p>
</div>
$form->field($model, 'map')->textInput(['maxlength' => true])
Answer the question
In order to leave comments, you need to log in
What do you think it means to pass a variable from JavaScript to ActiveForm? JavaScript works on the client side, php (which forms the ActiveForm) on the server side. Do you want to write the result of your js script execution in the form input field? then implement it in js, for example:$("#latlongmet").val(value);
How to pass this variable to ActiveForm
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question