How to take input values and concatenate them Javascript

Asked

Viewed 80 times

2

I’m doing it, but it’s not working

var nomeRua = document.getElementById('nomeRua').value();
var nomeBairro = document.getElementById('nomeBairro').value();
var uf = document.getElementById('uf').value();
var nomeCidade = document.getElementById('nomeCidade').value();
geocoder.geocode({ 'address': endereco + nomeRua + ", " + nomeBairro + ", " + uf + ", " + nomeCidade }, function (results, status) {

(...)
  • 1

    Use only .value; and not .value();. Another thing, I don’t see where the endereco ?

  • 1

    Thank you. The address is elsewhere

1 answer

5


What you seek is the attribute .value and not a method like .val(); jQuery or getValue(); of other libraries.

Changing this should solve it. By the way, a suggestion for this concatenation to be more readable::

var geoCode = [endereco + nomeRua, nomeBairro, uf, nomeCidade].join(', ');
geocoder.geocode({ 'address': geoCode }, function (results, status) {
  • Thanks for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.