javascript - Can anyone help me make the search bar work as I now have the JS prompt? -


i have created small program pulls youtube api allows search random video whatever title enter when prompted. goal have work search engine. make search bar input instead of alert prompt window. similarly, make "find" button act "ok" button on prompt alert window when run program javascript in jsbin. can point me in proper direction accomplish this? here jsbin. assuming can use sort of onclick function button, not totally sure how implement , call on. thank you!

ps. i'm know this, in case... make sure run program in jsbin "run js."

you can add onclick listener find button , trigger code when clicks. can value of search input instead of prompt:

javascript:

function search() {     var api_key;      api_key = "aizasydiuekwoldcb9qgrreosaiyu2nlj8u-03c";      var search_term = document.getelementbyid("searchterm").value;      function onsuccess(data){         console.log(data);         var obj = data.id;         console.log (data.items[0].id.videoid);          video_url = 'http://www.youtube.com/embed/' + data.items[0].id.videoid     +'?autoplay=1';          video.src = video_url;     }      var youtube_url = 'https://www.googleapis.com/youtube/v3/search?part=id&q=' +search_term +'&maxresults=1&key=' +api_key;      var video_url = 'http://www.youtube.com/embed/' +"iq1_aclevvo"+'?autoplay=1';        $.ajax({       method:'get',       url: youtube_url,       success: onsuccess     });  } 

html:

<button type="button" id="search" onclick="search()">find</button> 

jsbin


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -