samash samash - 1 year ago 68
Javascript Question

wants to replace the iframe based on Onlclick

I wants to replace the iframe, if user clicks on getPrice button again by selecting different input.I have written code and tried several things but nothing worked out. everytime I cant use document.body.appendchild(). My code is below. Please suggest here.

function getPrice()[
var ifrm = document.createElement('iframe'); = "frameID";
ifrm.setAttribute('src', ' East
ifrm.setAttribute('align', 'right');
//ifrm.setAttribute('marginheight', '50'); "auto";
ifrm.scrolling="no"; "0"; "0";
//document.body.insertBefore(ifrm, document.body.firstChild);
alert("Else"); // I am getting control till here but what code to replace the existing iframe.
//var item = document.getElementById("frameID").childNodes[0];

//ifrm.parentNode.replaceChild(ifrm, ifrm);

Answer Source

If you want to update the iframe content, you just need to use something like this :

function updateIframeSrc(newSrc) {
    document.getElementById("frameID").src = newSrc;

EDIT : Add exemple with HTML declaration to answer a comment.

<div class="frameClass">
    <iframe id="frameID" width="100%" height="1080" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download