I'm doing a PivotTable where the data comes from the database, and the user has the ability to edit that data. This data coming from the database is within <div>
.
Next to this data has a Editar
button where it changes the tag <div>
by a <input>
, and another button Salvar
appears, so far everything is right.
But when I click save it calls a function, where it gets the value
of this <input>
to update, only it is taking the old value, not the new one.
I want to know how to get this new data that the user 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.