I have a page which generates comboboxes dynamically inside IFrames.. Now when I select the combo inside the IFrame I want to pass the value back to my parent window... Ultimately I need to INSERT all the values into my database, but I can't INSERT the selections inside the IFRAME.

So far I have written two javascript onchange functions which retrieve the values I need from within the IFRAME.. My OnChange Event shows a popup box with the correct variable... Now I have to get that variable to my parent window :confused:

Then in the parent frame of the iframe, you can access the copy of the iframe variable using myPARENTframeVar. Also, you can skip the whole process and grab the iframe variable from the parent frame using this, assuming you've named the IFRAME 'myIFRAME'.

Code:

alert(window.frames['myIFRAME'].myIFRAMEvar);

02-16-2007, 09:52 AM

mattv10

I tried both methods. and each alert box returns undefined?? Am I doing something wrong?

02-16-2007, 10:25 AM

toicontien

That all depends on when you're trying to access variables. The parent document loads before the iframe document, so if you try to access the iframe document before it loads, then you get undefined. Can you post the full HTML and JavaScript being used?

02-16-2007, 10:42 AM

mattv10

I'm not sure if this is exactly what I want to do.. Maybe you can throw some insight if you like after I explain. I have a form which has an IFRAME that dynamically populates a combobox based on a prior combobox selection. After I fill out the form I send all the values to a .asp page where I do REQUEST.FORM("value").ITEM....
After I was messing around with your above example I was wondering if this was the best and only method to go because once I pass the IFRAME Values to the parent page I need to pass them to the INSERT Page.. Is there an easier way of doing this?

02-16-2007, 11:36 AM

toicontien

We need to see the full HTML and JavaScript. I'm out of ideas until I see some code.

02-16-2007, 11:59 AM

mattv10

Ok here is my code.. I'm going to try to limit the amount of code so if you need more just ask...

My Javascript Function in my parent.html (My Form)

Code:

function getIFrameVar(){ window.frames['jobFrame'].getJob();}

My Javascript Function in my IFRAME (On the same Form)

Code:

function getJob(job){
var JOB = job;
alert(JOB);
}

My Onchange event that passes the IFRAME ComboBox Selection to the getJob Function

Code:

<select name="selJob" onChange='getJob(selJob.value)'>

Now, just to test this I declared an onClick Event to a button on my parent page after my IFRAME would be generated to see if I successfully passed the value to my parent function.. However, it returns an alertbox that says "undefined"..

If I can get this alertbox to show my value I want to pass the variable between these functions and submit them with my form when I hit the add button...