Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing controls within Iframe from the page in IFrames source

Status
Not open for further replies.

DevGirl

Programmer
Jan 12, 2006
8
US
Hi,

I am designing an asp.Net page. I am using IE tabstrip. When user clicks on each tab, I call a IFrame with src = "ChildWebForm.aspx"

<iframe name= "IFrame1" id = "IFrame1" src="ChildWebForm.aspx" frameborder="0" width="100%" height="700px" scrolling="no"></iframe>

Now I am adding controls to My ChildWebForm. I added a few radio buttons. And I want to write some javascript.

I tried,
var doc = document.frames('IFrame1').document
If(doc.getElementbyID("radiobutton1").checked == true)
{alert ("I have clicked radiobutton1")}


This gives me an error.

How do I access the controls within the Iframe of my document?

 
Use square brackets around 'IFrame1' (where you currently use parentheses).

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Thanks. I could also use document.all['id'] right?
 
document.all is the devil - don't use it


it's VERY non-standard and will break in most other non-IE browsers

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
I tried the square brackets

function ShowFinancialData()
{
alert("blah")
var doc = document.frames['IFrame1'].document
alert("blah2")
}

Why does it never hit the second alert?
 
semi-colons?

...or maybe you don't really have an iframe named IFrame1? Do you have a JavaScript error (little yellow exclamation point)? Click on that. What does it say?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
By the way this function is in the childform.

This is the error.
document.frames.IFrame.document is not an object
 
Then you can use [red]parent.[/red]document.frames['IFrame1'].document ;-)

So is that it? Has your problem gone away?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Yep. Sorry. Thanx . It might be silly, but I am learning as we speak :)

One other issue I am having is refreshing the childform. Can u tell me how will I refresh childform if I Refresh the parentForm?

This is a fast response site I must admit!!!!!!
 
If you refresh the parent form, the child form should have no choice but to refresh. If you want to refresh the child form by itself, you can...

(in the parent form)

document.frames['IFrame1'].document.location = document.frames['IFrame1'].document.location.href;

(in the child form)

document.location = document.location.href;

Is this what you're asking?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
See here is what is happening.

When I am refreshing parentpage, I am not seeing my childpage at all.

parentpage has tabs, each tab points to a page
<ucIE:MultiPage id="mp2" runat="server" Width="100%" Visible="true" BorderWidth="0px">
<ucIE:pageView>
<iframe name= "IFrame1" id = "IFrame1" src="RiskAssessment.aspx" frameborder="0" width="100%" height="700px" scrolling="no"></iframe>
</ucIE:pageView>
</ucIE:MultiPage>


childpage
has panels which I show according to the radio button selected. When I refresh the parentpage. I see nothing in the childtab.
 
If you have a radio button checked in the parent page when the screen draws, you can simulate what happens when you click it by getting the radio button object and using the click() function:

myRadioButton.click();

If clicking the radio button fills in the child frame appropriately, then this should do the trick for you.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top