I need to replace iframe src acording to user input. I need some if else but not sure what to do with vars - I'm noob. Here is a code so far:
<div>
<h3>Some Header</h3>
<input type="text" size="25" id="inputTxt" value="">
<button onclick="myFunc()">go</button>
<br>
<br>
<div id="myDiv"></div>
<script>
function myFunc() {
var word = document.getElementById("inputTxt").value;
//if iframe (iframeClass) exists - replace with new one - else make new one...
var someNewFrame = document.createElement("iframe");
someNewFrame.setAttribute("class", "iframeClass");
someNewFrame.setAttribute("src", "http://someones.com/next/staters/" + word );
var newFrame = document.getElementById("myDiv");
newFrame.appendChild(someNewFrame);
}
</script>
</div>
Aucun commentaire:
Enregistrer un commentaire