Reputation: 1
I want to make an input that embeds a youtube video by entering a video id. This is what I tried, but it didn't work
HTML
<form action="http://www.youtube.com/embed/">
<input class="EnterID" type="text" id="txtSRC" />
<input class="submitid" type="button" value="Submit" onclick="SetSrc()" />
</form>
<iframe id="myIfreme" src="" frameborder="0" marginwidth="0" scrolling="yes" height="420" width="640"></iframe>
JS
<script type="text/javascript">
function SetSrc() {
document.getElementById("myIfreme").src = document.getElementById("txtSRC").value;
}
</script>
Upvotes: 0
Views: 714
Reputation: 35096
A couple of things:
Add the event object, call preventDefault()
on it, and then use document.location = ...;
function SetSrc(e) {
e.preventDefault();
document.getElementById("myIfreme").src = document.getElementById("txtSRC").value;
document.location = ...;
}
Upvotes: 1
Reputation: 76
Why does action have the url to be prepended? It should be in the javascript code like this:
<script type="text/javascript">
function SetSrc() {
document.getElementById("myIfreme").src = "http://www.youtube.com/embed/" + document.getElementById("txtSRC").value;
}
</script>
Upvotes: 0