2

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;
amelie
  • 289
  • 3
  • 16

3 Answers3

3

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.

YakovL
  • 7,557
  • 12
  • 62
  • 102
3

Try this - Form fields have value attributes, TDs not:

document.getElementById("start-e").value  = document.getElementById("start-1").getAttribute('value');
mplungjan
  • 169,008
  • 28
  • 173
  • 236
santho
  • 366
  • 2
  • 16
2

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');

Manny
  • 149
  • 5