2

I want to change src of iframe after button click. i cant find a solution

     <iframe id="Pencere" name="window" src="https://stackoverflow.com/" ></iframe>
     <input id="number" name="Number" type="text" >            
     <input id="button" class="button button1" type="button" value=" Jump " onclick="javascript:jump()"/>

     <script type="text/javascript">
     function jump()
      {              
        var number= document.getElementById("number").value;
        var url = "https://www.otherwebsite.com/"+number+"/1";
        document.getElementById("Pencere").src = url;
      }  
</script>

Result after button click: result after button click

3
  • What do you want to do? Commented Dec 4, 2019 at 12:59
  • i want to go to an other website in iframe with an input variable on button click Commented Dec 4, 2019 at 13:03
  • You are doing good. but first, check if there is exist the URL which you provide in the var url Commented Dec 4, 2019 at 13:06

1 Answer 1

2

function newSrc() {
  var e = document.getElementById("MySelectMenu");
  var newSrc = e.options[e.selectedIndex].value;
  document.getElementById("MyFrame").src=newSrc;
}
<iframe src="https://beamtic.com/" style="width:450px;height:450px;overflow:scroll;" id="MyFrame"></iframe>
<select id="MySelectMenu">
  <option value="https://beamtic.com/">Beamtic</option>
  <option value="https://fr.wikipedia.org/wiki/Main_Page">Wiki</option>
</select>
<button onClick="newSrc();">Change Iframe Src</button>

Hope you are looking for this kind of functionality

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.