Home > Software engineering >  How to embed video using input tag
How to embed video using input tag

Time:11-30

I want to embed the YouTube video by iframe using input tag.

But it's not working where's the mistake - **The entered URL is :- ** https://www.youtube.com/embed/G20AHZc_sfM

Code in Body tag :-

    <input id="url" type="url" placeholder="Video url">
    
    <button onclick="emb()">Embed video</button>
    
    <div id="link"></div>

Code in script :-

function emb(){
     var iframe,  urrl;
     var link= document.getElementById('url')
    iframe= document.querySelector("#link");
    
    urrl = `<center><iframe width="480" height="360" src="${link}"></iframe></center>`
    
    iframe.innerHTML = urrl;
            
        }

CodePudding user response:

You can't get the value of an input just by selecting it. Use the value property in link:

var link = document.getElementById('url').value;
  • Related