4
I’m making a dynamic table where the data comes from the database, and the user has the possibility to edit this data. This data coming from the bank is inside <div>
.
Next to these dice is a button Editar
where it changes the tag <div>
by a <input>
, and another boot appears Salvar
, so far all right.
Only when I click save it calls a function, where it picks up the value
of this <input>
to update, only he is taking the old and not the new.
I want to know how to get this new data that the user has typed.
Here is the code:
function Editar(){
//armazena o elemento div em uma variavel
var data = document.getElementById('data');
//muda a div para um campo, onde o usuario digita uma nova data
data.innerHTML = "<input type='text' name='data' value='" + data.innerHTML +"' id='dataVal'>";
//armazena a data digitada na variavel
dataVal = document.getElementById('dataVal').value;
}
function Salvar(){
console.log(dataVal);
}
So instead of giving me the new date, it returns the old date.