By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

dynamic iframes...

P: n/a
I need to replace iframes acc. to what option user chooses in a sel
obj.. but figured have to load a blank iframe when pg loads so I can
replace it.. (iframe gets put in a pre-existing div..) this is
approach.. I'm having some problems and would appreciate some help..
thank you very much...

var selItem;
var ifrCurr;
var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to load a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChild( ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();
function pricing() { // load iframes dynamically..
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';

document.getElementById("divPricing").appendChild( ifr);
// works fine here....

// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances

Sep 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Frances wrote:
I need to replace iframes acc. to what option user chooses in a sel
obj.. but figured have to load a blank iframe when pg loads so I can
replace it.. (iframe gets put in a pre-existing div..) this is
approach.. I'm having some problems and would appreciate some help..
thank you very much...

var selItem;
var ifrCurr;
var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to load a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChild( ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();
function pricing() { // load iframes dynamically..
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';

document.getElementById("divPricing").appendChild( ifr);
// works fine here....

// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances

this will not work, as users could change iframe even after they have
already chosen one.. I need to detect what iframe is loaded (i.e., what
FILE is loaded in iframe..) in order to replace it.. again thank you
very much...
Sep 22 '05 #2

P: n/a

Frances wrote:
I need to replace iframes acc. to what option user chooses in a sel
obj.. but figured have to load a blank iframe when pg loads so I can
replace it.. (iframe gets put in a pre-existing div..) this is
approach.. I'm having some problems and would appreciate some help..
thank you very much...

var selItem;
Do you still need selItem to be a global variable? It seems you're
only using it in your pricing() function.
var ifrCurr;
var ifrCurr = null;
var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to load a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChild( ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();
I believe you don't need to load a blank iframe. So you can remove
that line and the above function.


function pricing() { // load iframes dynamically..
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';

document.getElementById("divPricing").appendChild( ifr);
// works fine here....

// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances


You should code defensively. Ensure that you actually have an object.

function replaceIFrame()
{
if(div)
{
var selItem = document.getElementById("product").value;
var newifr = document.createElement("iframe");
newifr.src = 'iframes/' + selItem + '.html';

if(ifrCurr == null)
{
ifrCurr = div.appendChild(newifr);
}
else
{
div.replaceChild(newifr, ifrCurr);
ifrCurr = newifr;
}
}
}

Sep 22 '05 #3

P: n/a
web.dev wrote:
Frances wrote:
I need to replace iframes acc. to what option user chooses in a sel
obj.. but figured have to load a blank iframe when pg loads so I can
replace it.. (iframe gets put in a pre-existing div..) this is
approach.. I'm having some problems and would appreciate some help..
thank you very much...

var selItem;

Do you still need selItem to be a global variable? It seems you're
only using it in your pricing() function.

var ifrCurr;

var ifrCurr = null;

var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to load a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChil d(ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();

I believe you don't need to load a blank iframe. So you can remove
that line and the above function.


function pricing() { // load iframes dynamically..
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';

document.getElementById("divPricing").appendChild( ifr);
// works fine here....

// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances

You should code defensively. Ensure that you actually have an object.

function replaceIFrame()
{
if(div)
{
var selItem = document.getElementById("product").value;
var newifr = document.createElement("iframe");
newifr.src = 'iframes/' + selItem + '.html';

if(ifrCurr == null)
{
ifrCurr = div.appendChild(newifr);
}
else
{
div.replaceChild(newifr, ifrCurr);
ifrCurr = newifr;
}
}
}


thank you VERY MUCH, web.dev......:)

following yr post this is what I have now..

function pricing() {
//if (div) {
var div = document.getElementById("divPricing");
var selItem = document.getElementById("product").value;
var ifrCurr = null;
var ifrNew = document.createElement("iframe");
ifrNew.src = 'iframes/' + selItem + '.html';

if (ifrCurr == null) {
ifrCurr = div.appendChild(ifrNew);
} else {
div.replaceChild(ifrNew,ifrCurr);
ifrCurr = ifrNew;
}
// }
}

but it still puts new iframe NEXT TO current one, not on top...

(had to take out if(div) line, script did not work at all (did not load
iframe at all) if I left it in... (??) have TONS of divs on this page,
so probably don't need this.. (it detects whether or not there are any
divs on page, right?)

again many thanks.... Frances
Sep 22 '05 #4

P: n/a

Frances wrote:
web.dev wrote:
Frances wrote:
I need to replace iframes acc. to what option user chooses in a sel
obj.. but figured have to load a blank iframe when pg loads so I can
replace it.. (iframe gets put in a pre-existing div..) this is
approach.. I'm having some problems and would appreciate some help..
thank you very much...

var selItem;

Do you still need selItem to be a global variable? It seems you're
only using it in your pricing() function.

var ifrCurr;

var ifrCurr = null;

var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to load a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChil d(ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();

I believe you don't need to load a blank iframe. So you can remove
that line and the above function.


function pricing() { // load iframes dynamically..
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';

document.getElementById("divPricing").appendChild( ifr);
// works fine here....

// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances

You should code defensively. Ensure that you actually have an object.

function replaceIFrame()
{
if(div)
{
var selItem = document.getElementById("product").value;
var newifr = document.createElement("iframe");
newifr.src = 'iframes/' + selItem + '.html';

if(ifrCurr == null)
{
ifrCurr = div.appendChild(newifr);
}
else
{
div.replaceChild(newifr, ifrCurr);
ifrCurr = newifr;
}
}
}


thank you VERY MUCH, web.dev......:)

following yr post this is what I have now..


Don't forget to include:

var div = document.getElementById("divPricing");
function pricing() {
//if (div) {
var div = document.getElementById("divPricing");
var selItem = document.getElementById("product").value;
var ifrCurr = null;
var ifrNew = document.createElement("iframe");
ifrNew.src = 'iframes/' + selItem + '.html';

if (ifrCurr == null) {
ifrCurr = div.appendChild(ifrNew);
} else {
div.replaceChild(ifrNew,ifrCurr);
ifrCurr = ifrNew;
}
// }
}

but it still puts new iframe NEXT TO current one, not on top...

(had to take out if(div) line, script did not work at all (did not load
iframe at all) if I left it in... (??) have TONS of divs on this page,
so probably don't need this.. (it detects whether or not there are any
divs on page, right?)

again many thanks.... Frances


The if(div) statement is there to check if an object exists.

Sep 22 '05 #5

P: n/a

Concider this :
var Banana = document.getElementById("Orange");
/*
This has created var var called Banana.
And stored to it a reference to an element with the id="Orange"
*/

if( Banana )
{
/*
If you reach this point there's an element on the page
with an id="Orange";
*/
}
else
{
/*
If you reach here there's no element on in the DOM
with the id="Orange";
*/
}
OK so that's why webdev was used this

function replaceIFrame()
{
var div = document.getElementById("divPricing");
if(div)
{ ...
http://km0ti0n.blunted.co.uk/

Sep 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.