I am trying to use Moovit embedded services.
I want to put an origin and destination address automatically.
So, I've this function in a JS file that receives the origin address and open a new window.
I don't know how to get this data from JS in HTML.
function print_moovitmap(origin) {
origin_ad = origin; //Origin_ad is global
window.open('/new', '_blank');
}
I am working with Django. I have also origin_ad in a form field with an Id but I couldn't access to this form field in HTML. It gives me null.
origin_address=forms.CharField(max_length=200,widget=forms.TextInput(attrs={'class':'data_aux data','id':'origin_address'}))
In HTML (null):
console.log(document.getElementById('origin_address'));
And in new.html:
<div class="mv-wtp" id="mapa_moovit" data-to='' data-lang="es">
<script>
var m = document.getElementById('mapa_moovit');
m.setAttribute("data-to", "Central Park");
m.setAttribute("data-from", "Times Sq");
</script>
{% load static %}
<script src="{% static 'moovit_script.js'%}"></script>
</div>
I need to set attribute data-from to origin_ad but I don't know how.
Thank you.