jQuery cutting words with space

Asked

Viewed 112 times

4

I have a screen where the lines are loaded according to the data of the database and for this I have a PHP+jQuery and related to the creation of the same. What happens is that the array that sends the data comes correctly, but at load time the field is only fed by the first word, if there are spaces it ignores. Below follows:

Array:

[{"nome":"DIEGO LUIS VENUZKA","codigo":"5357","cracha":"6246286874","situacao":"ATIVO","ASO":"30\/04
\/18","id":"1","descricao":"PONTE ROLANTE (NR11 E NR12)","validade":"06\/05\/18"},{"nome":"DIEGO LUIS
 VENUZKA","codigo":"5357","cracha":"6246286874","situacao":"ATIVO","ASO":"30\/04\/18","id":"4","descricao"
:"EMPILHADEIRA A GAS (NR11 E NR12)","validade":"06\/05\/18"}]

Part of the code that loads the data from this array:

for(var i = 0;i<data.length;i++){
  HTML += "<tr><td><input type = 'text' size = '3' name = 'id[]' id = 'id[]' value=" + data[i].id + " readonly></td>";
  HTML += "<td><input type = 'text' size = '40' name = 'descricao[]' id = 'descricao[]' value=" + data[i].descricao + " readonly></td>";
  HTML += "<td><input type = 'text' size = '10' name = 'validade[]' id = 'validade[]' value=" + data[i].validade + " readonly></td>";
}

Upshot:

inserir a descrição da imagem aqui

Any suggestions?

1 answer

3


Turns out you’re not passing the value inside quotes, example:

<input type="text" value=Stack Overflow Português />

<input type="text" value="Stack Overflow Português" />

Change to:

for(var i = 0;i<data.length;i++){
  HTML += '<tr><td><input type="text" size="3" name="id[]" id="id[]" value="' + data[i].id + '" readonly></td>';
  HTML += '<td><input type="text" name="descricao[]" id="descricao[]" value="' + data[i].descricao + '" readonly></td>';
  HTML += '<td><input type="text" size="10" name="validade[]" id="validade[]" value="' + data[i].validade + '" readonly></td>';
}
  • Cara..... I since 8 am breaking me and you give me a solution so obvious...that shame....hehehe. Thank you very much!!!!!

  • 1

    It turns out, in the middle of so many single double quotes there was no missing any.

Browser other questions tagged

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