Youtube video on load through Jquery/JS

Posted by jonthecoder2346 on Stack Overflow See other posts from Stack Overflow or by jonthecoder2346
Published on 2012-06-04T22:27:12Z Indexed on 2012/06/04 22:40 UTC
Read the original article Hit count: 225

My goal is to display a youtube video through a javascript function that will read the embedded code and load the video automatically in the div assigned. But I am not getting anything shown in the div assigned for the video. Is it because it has to be triggered by a button click?

<script type="text/javascript">
                            var last_cnad_text_1 = '';
                            var options_cnad_text_1 = {
                            embedMethod:'fill',
                            maxWidth:320,
                            maxHeight: 320
                            };
                            function loadVideo()
                            {
                            val = $('#cnad_text_1').val();
                            if ( val != '' && val != last_cnad_text_1 )
                            {
                            last_cnad_text_1 = val;
                            $("#embed_cnad_text_1").oembed(val,options_cnad_text_1);
                            }
                            }
                            $(function(){
                            $('#cnad_text_1').keydown(loadVideo());
                            $('#cnad_text_1').click(loadVideo());
                            $('#cnad_text_1').change(loadVideo());
                            }); 
                        </script>  
<body>


                <input id="cnad_text_1" type="text" value="" size="60" name="cnad[text_1]">
                <div id="embed_cnad_text_1"></div>
</body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery