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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change background of frame_a from value in frame_b 1

Status
Not open for further replies.

jcgroove

Technical User
Oct 8, 2008
4
So what I'm trying to do is change the background color or image of frame_a based on a hidden form id value in frame_b. I haven't been able to get it to work in firefox. Can anyone help me please!

Here is the html for the frameset page:

<html>

<frameset rows="25%,75%">

<frame name="frame_a" src="frame_a.htm">
<frame name="frame_b" src="frame_b.htm">


</frameset>

</html>

Here is the html for frame_a:

<html>
<head>
<script>
function changeBG(){
if (document.all) {
if (frame_b.document.nodeForm.classification_id.value = "C")
document.body.style.background = "/blue.png";
else if (document.nodeForm.classification_id.value = "S")
document.body.style.background = "/red.png";
else
document.body.style.background = "/gray.png";
}
}
</script>

</HEAD>
<BODY onload="changeBG()">

<h3>Frame A</h3>

</body>
</html>

And here is the html for frame_b:

<form name="nodeForm">
<input type=hidden name=title value="MENUBAR CONTROLS - COMMON CONTROLS">
<input type=hidden name=node_id value="1000050703">
<input type=hidden name=class_id value="245">
<input type=hidden name=edit_type_id value="G">
<input type=hidden name=review_id value="P">
<input type=hidden name=classification_id value="S">
</form>

<html>
<body bgcolor="#EBC79E">

<h3>Frame B</h3>

</body>
</html>
 
You don't specify if it works in IE or another browser neither the behaviour you get in FF.

A good starting point would be to use documents.frames['frame name'].

Cheers,
Dian
 
I've gotten this functionality to work in IE with a very similar script. Just not having luck with FF.

Thanks for any help!
 
Remove this line:

Code:
if (document.all) {

It's very unnecessary these days, and you're not even using the .all collection after performing the test.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
[0]
>I haven't been able to get it to work in firefox.
>I've gotten this functionality to work in IE with a very similar script. Just not having luck with FF.

Why do you need a "similar" script for ie to work? I don't even think it works "proper" for any. In particular, you have to make a handle the timing problem as an essential ingrediant for anything to work properly.

[1] Since frame_b is in a frameset frame which comes after the frame_a. If you use onload in frame_a to call frame_b controls, it may more often than not _not_ ready. You have to handle it properly.

[2] It is not background style, it is more plausibly backgroundImage which requires different syntax.

[3] Hence the frame_a source page should have the onload function scripted like this, minimally. Besides, it should then be cross-browser applicable.
[tt]
function changeBG(){
[red]if (parent.frames["frame_b"].document && parent.frames["frame_b"].document.nodeForm) {[/red]
if (parent.frames["frame_b"].document.nodeForm.classification_id.value [red]==[/red] "C") {
document.body.style.background[red]Image = "url(/blue.png)"[/red];
} else if (parent.frames["frame_b"].document.nodeForm.classification_id.value [red]==[/red] "S") {
document.body.style.backgroundImage = "url(/red.png)";
} else {
document.body.style.backgroundImage = "url(/gray.png)";
}
[red]} else {
setTimeout("changeBG()",100);
}[/red]
}
[/tt]
[4] frame_b has a form nodeForm appears like a cancer to the page. That is not good scripting.
 
That worked!
Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top