Reputation: 289
I've got a table which displays datetime like this:
<td id="start-1" value ="2017-03-15T00:00">2017-03-20 20:00:00</td>
When user wants to edit row, a modal window
will be opened with filled data. But the value of time is not passed to modal window
(datetime-local is shown blank).
However if the string "2017-03-15T00:00" is passed directly to inside script as below:
document.getElementById("start-e").value = "2017-03-15T00:00";
, it does show it, but the code below does not work:
document.getElementById("start-e").value = document.getElementById("start-1").value;
Upvotes: 2
Views: 327
Reputation: 386
Try this - Form fields have value
attributes, TDs not:
document.getElementById("start-e").value = document.getElementById("start-1").getAttribute('value');
Upvotes: 3
Reputation: 149
Generally DOM elements in javascript have no value
property. I guess the start-e
is an input, which does have and that's why you can use document.getElementById("start-e").value
(see: https://developer.mozilla.org/en-US/docs/Web/API/Element)
Otherwise you need to use the attributes, like @santho suggested.
His answer will work:document.getElementById("start-e").value = document.getElementById("start-1").getAttribute('value');
Upvotes: 2
Reputation: 31
You have to change the code as below:
document.getElementById("start-e").value = document.getElementById("start-1").innerHTML;
as td
is not a control, it is an html tag. You have to use .innerHTML
to get its child content.
Upvotes: 3