Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to embed video using input tag

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 :-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    <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;
            
        }

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading