-3

I am trying to display video duration and I took reference from this answer Get video duration when input a video file given by Kaiido. Here is the code:

<script>
          var myVideos = [];

          window.URL = window.URL || window.webkitURL;

          document.getElementById('fileUp').onchange = setFileInfo;

          function setFileInfo() {
            var files = this.files;
            myVideos.push(files[0]);
            var video = document.createElement('video');
            video.preload = 'metadata';

            video.onloadedmetadata = function() {
              window.URL.revokeObjectURL(video.src);
              var duration = video.duration;
              var duration = (new Date).clearTime()
                                .addSeconds(duration)
                                .toString('H:mm:ss');

              myVideos[myVideos.length - 1].duration = duration;
              updateInfos();
            }

            video.src = URL.createObjectURL(files[0]);;
          }


          function updateInfos() {
            var infos = document.getElementById('infos');
            infos.textContent = "";
            for (var i = 0; i < myVideos.length; i++) {
              infos.textContent += myVideos[i].duration + '\n';
            }
          }
</script>

However, I want to insert the value inside tag rather than in tag.

I tried using input tag in place of pre tag but it did not work.

  • Welcome to Stack Overflow! Please take the [tour] (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). We can't help you with code we can't see. Ensure the full content of your question is **in** your question, not just linked. Two reasons: People shouldn't have to go off-site to help you; and links rot, making the question and its answers useless to people in the future. – T.J. Crowder Jan 13 '19 at 14:59
  • Thank you T.J. Crowder. It worked! –  Jan 13 '19 at 15:02
  • The point of an `input` is to let the user input something, it is highly inappropriate to use it to display output! – Quentin Jan 13 '19 at 15:03

1 Answers1

1

If it works for a pre and not for an input, you have the converse of this problem: You're using innerHTML (or innerText or textContent, etc.) when you should be using value.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875