Syntax error concatenation [closed]

-2

My function returns the following error:

  

Uncaught SyntaxError: Unexpected string

How can I fix it?

function setarRegistro() {
    campos = "teste="+encodeURI(document.getElementById('teste').value).
    "&nome="+encodeURI(document.getElementById('nome').value).
    "&sobrenome="+encodeURI(document.getElementById('sobrenome').value).
    "&usuario="+encodeURI(document.getElementById('usuario').value).
    "&email="+encodeURI(document.getElementById('email').value).
    "&senha="+encodeURI(document.getElementById('senha').value);
}
    
asked by anonymous 19.07.2018 / 22:13

3 answers

0

Use "+" to concatenate in JavaScript, the "." is used to access the property or function of an object.

    
19.07.2018 / 22:24
0

In javascript the concatenation operator is +. Just replace the. by + as below.

function setarRegistro() {
   campos = "teste="+encodeURI(document.getElementById('teste').value)+
   "&nome="+encodeURI(document.getElementById('nome').value)+
   "&sobrenome="+encodeURI(document.getElementById('sobrenome').value)+
   "&usuario="+encodeURI(document.getElementById('usuario').value)+
   "&email="+encodeURI(document.getElementById('email').value)+
   "&senha="+encodeURI(document.getElementById('senha').value);
}
    
19.07.2018 / 22:23
0

Response

In php you can concatenate with the "." in javascript should use "+" in your code are mixed.

function setarRegistro() {
    campos = "teste=" + encodeURI(document.getElementById('teste').value) +
    "&nome=" + encodeURI(document.getElementById('nome').value) +
    "&sobrenome=" + encodeURI(document.getElementById('sobrenome').value) +
    "&usuario=" + encodeURI(document.getElementById('usuario').value) +
    "&email=" + encodeURI(document.getElementById('email').value) +
    "&senha=" + encodeURI(document.getElementById('senha').value);
}
    
19.07.2018 / 22:23