PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

[FIXED] How to embed video using input tag

 April 15, 2022     embed, html, iframe, input, javascript     No comments   

Issue

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

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;


Answered By - code
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing