Referencing an image via ID on main page from second form

R

RWC

Hello,

I have a page connected to an SQL table. The page loops through, creating a
row for each record, displaying in image, the ID of which is set to the
record id. When I click a button to change the image, I'd like to refer to
the ID on the main page, but change the image on the main page. Any idea
how to do this?

Example is as follows

Record 1 ID=1 NAME=Image1 Src=bird.jpg
Record 2 ID=2 NAME=Image1 Src=horse.jpg
Record 3 ID=3 NAME=Image1 Src=cow.jpg
When I open the child window and select a new image for Record 3, I'd like
to change the record 3 src to insect.jpg.

I've changed the value of things based on teh Name element but never the ID.
How do I do that?

Any help would be great!

Thanks in advance!
Rick
 
R

RobG

RWC said:
Hello,

I have a page connected to an SQL table. The page loops through, creating a
row for each record, displaying in image, the ID of which is set to the
record id. When I click a button to change the image, I'd like to refer to
the ID on the main page, but change the image on the main page. Any idea
how to do this?

Example is as follows

Record 1 ID=1 NAME=Image1 Src=bird.jpg
Record 2 ID=2 NAME=Image1 Src=horse.jpg
Record 3 ID=3 NAME=Image1 Src=cow.jpg

These are not valid id's. An id:

"...must begin with a letter ([A-Za-z]) and may be followed by any
number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".")"

Though they probably work in most browsers (but that doesn't make them
valid HTML).

Using identical names for the images will cause problems also, though
most browsers will tolerate it. Names on images should be unique.
Browsers will likely return the first image with the name, but you
should not depend on that behaviour.

Your HTML should look something like like:

<tr><td><img name="Image1" id="Image1" src="brid.jpg"></td></tr>
<tr><td><img name="Image2" id="Image2" src="horse.jpg"></td></tr>
<tr><td><img name="Image3" id="Image3" src="cow.jpg"></td></tr>

Others may comment on the use of tables for layout...
When I open the child window and select a new image for Record 3, I'd like
to change the record 3 src to insect.jpg.

I've changed the value of things based on teh Name element but never the ID.
How do I do that?

The easiest way is to use the images collection:

opener.document.images['Image3'].src = 'insect.jpg'
 
R

RWC

Excellent. Thanks Rob, I will give that a try.

Rick

RobG said:
RWC said:
Hello,

I have a page connected to an SQL table. The page loops through, creating a
row for each record, displaying in image, the ID of which is set to the
record id. When I click a button to change the image, I'd like to refer to
the ID on the main page, but change the image on the main page. Any idea
how to do this?

Example is as follows

Record 1 ID=1 NAME=Image1 Src=bird.jpg
Record 2 ID=2 NAME=Image1 Src=horse.jpg
Record 3 ID=3 NAME=Image1 Src=cow.jpg

These are not valid id's. An id:

"...must begin with a letter ([A-Za-z]) and may be followed by any
number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".")"

Though they probably work in most browsers (but that doesn't make them
valid HTML).

Using identical names for the images will cause problems also, though
most browsers will tolerate it. Names on images should be unique.
Browsers will likely return the first image with the name, but you
should not depend on that behaviour.

Your HTML should look something like like:

<tr><td><img name="Image1" id="Image1" src="brid.jpg"></td></tr>
<tr><td><img name="Image2" id="Image2" src="horse.jpg"></td></tr>
<tr><td><img name="Image3" id="Image3" src="cow.jpg"></td></tr>

Others may comment on the use of tables for layout...
When I open the child window and select a new image for Record 3, I'd like
to change the record 3 src to insect.jpg.

I've changed the value of things based on teh Name element but never the ID.
How do I do that?

The easiest way is to use the images collection:

opener.document.images['Image3'].src = 'insect.jpg'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top