1

i want the player to play a video with a video id specified by a user (an if specified be me would work) by an input code im not that great at coding, but this code

$('.col-sm-12').append('<div data-video="' + ytmusic + '" data-autoplay="0" data-loop="1" id="youtube-audio"> </div> <script src="https://www.youtube.com/iframe_api"></script> <script src="https://cdn.rawgit.com/labnol/files/master/yt.js"></script><input maxlength="40" type="text" placeholder="Music Video" id="ytmusic" name="ytmusic" class="form-control" style="color: rgb(255, 255, 255);">');

is working great (notice the ytmusic in the beginning)

I tried to make the variable set using many methods:

  1. var ytmusic = document.getElementsByName("ytmusic").value;

  2. var ytmusic = $('#ytmusic');

Let's say the ytmusic is rgW_I8saK1o , it will play the video https://www.youtube.com/watch?v=rgW_I8saK1o

this link shows the current shape of the code

(Image With Input At The End)

DoreM
  • 11
  • 2
  • @Barmar, that is not my question, it isnt related to it at all in fact. – DoreM Mar 29 '17 at 23:19
  • The problem is that you forgot to index the result of `getElementsByName`. You can't use `.value` without an index. – Barmar Mar 29 '17 at 23:20
  • You need to clarify the problem in the question. I don't see any explanation there, and I assumed the problem was that `document.getElementsByName("ytmusic").value` wasn't returning anything. – Barmar Mar 29 '17 at 23:22
  • i wanted the player to play a video with a video id specified by a user (an if specified be me would work) by an input code – DoreM Mar 29 '17 at 23:28
  • 2
    And what problem are you having? Don't put the explanation in a comment, edit the question to make it clear what you want to happen, what code you've written, and what it's doing wrong. See http://stackoverflow.com/help/how-to-ask – Barmar Mar 29 '17 at 23:30
  • the problem is i dont know what exactly to put at – DoreM Mar 30 '17 at 09:56
  • the problem is that i dont know what exactly do i put at (var ytmusic = ??????) – DoreM Mar 30 '17 at 09:56
  • i actually did try ti do document.getElementsByName("ytmusic")[0].value but it still didnt work – DoreM Mar 30 '17 at 09:58
  • If you want this to happen when the user clicks on something, you put it in the `$(selector).click()` handler. – Barmar Mar 30 '17 at 15:43
  • i want it to play a video based on the video ID – DoreM Mar 30 '17 at 21:57
  • So you should have a text input where the user enters the video ID, and a button they push to start playing. Put your code inside `$("#playButton").click(function() { ... });` – Barmar Mar 30 '17 at 22:53
  • i need a full answer, it is that the function is from a YouTube API, i dont know what to put in $("#playButton").click(function() { ... }); exactly, could you help me? – DoreM Apr 02 '17 at 12:59

0 Answers0