Click to See Complete Forum and Search --> : How to change text in child window?


rolas
10-21-2004, 01:01 PM
Hi,

I want to change text in my child window, but I can't figure out how, I've tried through <font> with 'id', I've tried using variable, but ... :( Help PLEASE !

Jona
10-21-2004, 01:04 PM
Why not just open a different URI in the same child window?

rolas
10-21-2004, 01:12 PM
I'm not even sure how this is going to help me, since I have an array with text info in my parent window and it needs to be changed as user clicks button.

Fang
10-21-2004, 01:13 PM
Change text in the child window from the opener(parent) window:
ChildWindowName.document.getElementById('ElementID').firstChild.data='New text';

Jona
10-21-2004, 01:14 PM
What about the poor 10% of people on the Internet who don't have JavaScript? Will this cause them not to be able to get content? If so, have you no pitty for these people?

rolas
10-21-2004, 01:15 PM
Maybe I expressed myself wrong: array stays always the same, but the data needs to go to child window.

rolas
10-21-2004, 01:53 PM
About 10% pooor Internet people.
They still will be able to see contents, but they won't be able to use all features - you see, I care about poor people :)

And I've tried Fang's line, but I still can't get it to work (I can't find usage description for GetElementById in my old 1999 book). Here is my simple code:

function GoLeft()
{
if (kuris > 1)
{
kuris = kuris - 1;
}
win.document.images(0).src = Src[kuris]; win.document.getElementsById('desc')firstChild.data = Txt[kuris];
}

Txt[] is my text array, 'desc' is my <font> id for the text to be changed.

Fang
10-21-2004, 02:00 PM
win.document.getElementById('desc').firstChild.data
and getElementById not getElementsById

rolas
10-21-2004, 02:06 PM
I've tried both ways, but still no luck :( Any ideas what can be wrong?

Fang
10-21-2004, 02:12 PM
Not without seeing your pages.

rolas
10-21-2004, 02:30 PM
Here is my code, I've deleted some not related parts, so it's easier to browse through code.


<html>
<head ID='mano'>
<title>Untitled</title>

<script language="JavaScript">
<!--

var Txt = new Object()

Txt[1] = "My text 1 ";
Txt[2] = "My text 2 ";
Txt[3] = "My text 3 ";
Txt[4] = "My text 4 ";


function ShowPic(number) {
win = window.open("", "GAL_P12", winOpts + ",width=708,height=548,top=" + Y + ",left=" + X);
win.focus()
win.document.open();

win.document.write(
"<html><head><title>Test</title></head>" +
"<body>" +

"<font id='desc' style='font-size : 10pt; font-style : italic; color : #EFE3AB'><b>" + Txt[number] + "</b></font>" +

"<a href='JavaScript:opener.GoLeft()'><img src='pcs/l_arrow.jpg'></a>" +

"<a href='JavaScript:opener.GoRight()'><img src='pcs/r_arrow.jpg'></a>" +

</body></html>");
win.document.close();
}


function GoLeft()
{
if (kuris > 1) {
kuris = kuris - 1;
}
win.document.images(0).src = Src[kuris]; // <--- This works
win.document.getElementById('desc').firstChild.data = Txt[kuris];
}

//-->
</script>

rolas
10-21-2004, 02:34 PM
I forgot to add line about declaring 'win' as global:

var win = new Object()

Fang
10-21-2004, 03:03 PM
var Txt = new Array();
and
<font> is not a valid element, use <p> or some other valid element.
and
firstChild will not work if 'desc' has a child <b>. Place the style bold in the 'desc' style.

rolas
10-21-2004, 03:34 PM
It works !!! Thank you, thank you :)
The problem was in <b>, I got rid of that and bolded through 'style'.