Forum Moderators: open

Message Too Old, No Replies

Swap Image Across Frames Using Checkbox

         

icon_kid

3:58 am on Aug 4, 2013 (gmt 0)

10+ Year Member



I'm trying to swap an image in one frame by using a check box in another frame. The following GIF animation simulates how this would look. It seems like there's only one image but in a working document there are two -- one is of an apple and the other is blank and fully transparent.

<snip>

The following link shows how the actual page works right now. I'm using a square containing the words "transparent image" as a temporary (and visable) place holder for the fully transparent one.

<snip>

On this test page you can try the check box -- it makes the apple appear but in the same frame as the check box. The appearance of the apple in this frame will be removed later but the code is in place for it to appear in the other frame too, but doesn't work.

The code for the frameset document is:
-------------------------------------------------------------------
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 DRAFT//EN">

<HTML>

<HEAD>
<TITLE>BROOKLYN</TITLE>
</HEAD>

<FRAMESET cols="200px, *">
<FRAME src="First_Frame_Source.html">
<FRAME src="Second_Frame_Source.html" name="Second_Frame">
</FRAMESET>

</HTML>
-------------------------------------------------------------------
One requirement for targeting the output of a form to another frame is that the target frame must be named, which I've done so -- as in [name="Second_Frame"].

The code for the frame containing the check box looks like this:
-------------------------------------------------------------------
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 DRAFT//EN">

<HTML>
<HEAD>
<TITLE>First Frame Source</TITLE>

<base target="Second_Frame">
</head>

<BODY bgcolor="#a1adc0" text="#000000" LINK="#8F8FFC" VLINK="#B67AF6" ALINK="#FFFFFF">
<font face="Arial, Helvetique, sans-serif" SIZE=2>

<p>
<form style='display:inline;' name="form-001" method="post" action="" target="Second_Frame">
<script type="text/javascript">
function processCheckbox(checkbox) {
if (checkbox.checked) {
image.src = "apple.png";
image.onclick = enabledClick;
} else {
image.src = "transparent_image.png";
image.onclick = null;
}
}
function enabledClick() {
alert("enabled!");
}
</script>

<input type="checkbox" onclick="processCheckbox(this);" target="Second_Frame">
</form>
&nbsp;
<img src="transparent_image.png" id="image">&nbsp;

</font>
</BODY>
</HTML>
-------------------------------------------------------------------
Various HTML help resources have suggested three different places where I could put a targeting statement to direct the output of the check box. I put such a statement in all three places for good measure; one between the HEAD tags (which is supposed to direct the output of ANY form in the document to the desired target), one in the form itself, and one for the 'input type' (the checkbox) but nothing works.

The code for the 'Second Frame' looks like this:
-------------------------------------------------------------------
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 DRAFT//EN">

<HTML>

<HEAD>
<TITLE>Second Frame Source</TITLE>
</head>

<BODY bgcolor="#505050" text="#c0c0c0" LINK="#8F8FFC">
<font face="Arial, Helvetique, sans-serif" SIZE=3>

<div class="row"><img src="transparent_image.png" id="image"/></div>

</font>
</BODY>
</HTML>
-------------------------------------------------------------------
Why the 'div' tags? -- that's because the final page will contain not one large image like this test page but over a hundred tiny 17 X 17 pixel images which must all sit ajacent to each other in a grid pattern with no spaces between them. Without 'div' tags, my browser puts a 1-pixel space around each image -- I left this in the test page to remind myself to keep it in the final document.

[edited by: incrediBILL at 6:27 am (utc) on Aug 15, 2013]
[edit reason] URls removed. Please see forum charter and TOS [/edit]

rainborick

6:41 am on Aug 4, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Leaving aside the issues with your HTML, there's some important information you need to provide before anyone can really help you.

You say that the final page will have over 100 images, but your code only shows one control - a single checkbox. Eventually, it would seem necessary to provide a mechanism to select which of those images is changed. I'm sure you'd agree that 100 checkboxes is impractical, so how is the final version supposed to work?

icon_kid

4:16 pm on Aug 4, 2013 (gmt 0)

10+ Year Member



I'm trying to make something similar to a 'Google My Map' but without the limitations of a Google Map. Below is a link to a screen shot of the map I made for the route I do in Staten Island, NY. There are two major limitations. One is that the list of locations in the left column can not be alphabetized for easy indexing. Each new address added to the list is placed at the bottom and can not be re-inserted anywhere else. The other major limitation is that you can not 'hide' any of the icons on the map -- once made, an icon is always visable. For Staten Island, for instance, there are around fifty destination points, however, only around ten need to be visited on any given day. Someone who is working out the 'way stops' for that day only needs to see the ten icons -- showing all fifty icons when there are only ten way stops means working around an unnessesarily clutered map.

<snip>

The next screen shot shows how my own such map is created. The map is covered with a grid work of tiny images. They are all the same image, just repeated across a map background of Brooklyn, NY and there are over three thousand of them. I put black edges on the otherwise blank image just for this screen shot so that you can see the actual pattern it makes -- the grid will be completely invisable in the final document. There's only one way point in the list but it will eventually stretch down to around a hundred. Each will have a check box, a unique icon next to it that will be associated the same icon to mark its location on the map, the name of the location and the address. As you can see, "Sussman" is checked and the icon appears in one of the squares on the map. It will dissapear when Sussman is unchecked

<snip>

Below is a link to the actual document I'm working on. If you hover the mouse over any spot within Brooklyn a 'title' balloon appears identifying that spot within a 17 X 17-pixel area. I'm aware that, for multiple pairs of image swaps, the transparent images for assigned locations must have unique names like the unique map icons will. For instance, the transparent image used for the 'Sussman' image swap will be called 'sussman.png' not 'blank.png.'

<snip>


The code for the frameset document looks like this:
----------------------------------------------------------------
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 DRAFT//EN">

<HTML>

<HEAD>
<TITLE>BROOKLYN</TITLE>
</HEAD>

<FRAMESET cols="200px, *">
<FRAME src="client_list.html" RESIZE SCROLLING=yes>
<FRAME src="BK-Map.html" name="BK-Map">
</FRAMESET>

</HTML>
----------------------------------------------------------------
The code for the 'Client List' document looks like this:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 DRAFT//EN">
<HTML>

<HEAD>
<TITLE>Client List</TITLE>

<link rel="stylesheet" type="text/css" href="sheet2.css">

<base target="BK-Map">

</head>

<BODY bgcolor="#a1adc0" text="#000000" LINK="#8F8FFC" VLINK="#B67AF6" ALINK="#FFFFFF">
<font face="Arial, Helvetique, sans-serif" SIZE=2>

<p>
<form style='display:inline;' name="form-001" method="post" action="" target="BK-Map">

<script type="text/javascript">
function processCheckbox(checkbox) {
if (checkbox.checked) {
image.src = "white_dot.png";
image.onclick = enabledClick;
} else {
image.src = "sussman.png";
image.onclick = null;
}
}
function enabledClick() {
alert("enabled!");
}
</script>

<input type="checkbox" onclick="processCheckbox(this);" target="BK-Map">
</form>
&nbsp;
<img src="sussman.png" id="image">&nbsp;
<font color="#2b3f80">
<b>Sussman</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1 Hanson Place

</font>
</BODY>
</HTML>
----------------------------------------------------------------
With over thirty-nine hundred lines in the 'map'document, it is too long to reprint here. Instead I'll show you a portion of it showing the 'Sussman' entry at line 1259.

The Javascript section of the 'Client List' document is supposed to search for the blank image called 'sussman.png' in this document -- and swap that with the image called 'white_dot.png.'

/><img src="blank.png" title="AY-007"
/><img src="blank.png" title="AY-008"
/><img src="blank.png" title="AY-009"
/><img src="blank.png" title="AY-010"
/><img src="sussman.png" id="image" title="Sussman - 1 Hanson Pl"
/><img src="blank.png" title="AY-012"
/><img src="blank.png" title="AY-013"
/><img src="blank.png" title="AY-014"
/><img src="blank.png" title="AY-015"


If anyone knows of a more efficient way to create a map utility like this one, I'd like to be told about it.

[edited by: incrediBILL at 6:32 am (utc) on Aug 15, 2013]
[edit reason] URls removed. Please see forum charter and TOS [/edit]

icon_kid

5:34 am on Aug 17, 2013 (gmt 0)

10+ Year Member



I had to abandon the use of frames for this project because I could not find any code that would actually target a named frame from a 'checkbox event', so I decided to go with tables instead. There were problems with tables too but the project is progressing. The next issue for me is 'multiple image flips.'

The picture below illustrates three separate image swaps.

-- When checkbox "A" is checked, image "1" turns into image "2" --

-- When checkbox "B" is checked, image "3" turns into image "4" --

-- When checkbox "C" is checked, image "5" turns into image "6" --

<snip>

The problem with the code I have now is that it works for the flip of only the first pair of images -- it won't flip any more pairs after the first one even though I've inserted more image names into it. The code that works for flipping only one image pair from a check box looks like this:

-----------------------------------------
*head*
<script type="text/javascript">
function processCheckbox(checkbox) {
if (checkbox.checked) {
image.src = "ICONS/white_dot.png";
image.onclick = enabledClick;
} else {
image.src = "ICONS/sussman.png";
image.onclick = null;
}
}
function enabledClick() {
alert("enabled!");
}
</script>
-----------------------------------------
*body
<img src="ICONS/sussman.png" id="image""
-----------------------------------------

By the way, the three empty circles represent completely blank, transparent images to which the filled circles will take their place. As mentioned earlier in this thread, it's understood that the blank images must all have unique file names as well as the ones they swap with.

I'm looking for a solution similar to the one that cmarshall gave to praxiz
for the same 'single-swap-only' problem (in a post from March, 2007):

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
img1 = "images/white-flag.gif";
img2 = "images/red-flag.gif";
function chng(c_img) {
if (c_img.src.indexOf(img1)!= -1) c_img.src = img2;
else c_img.src = img1;
}
</Script>
</head>
<body>
<img src="images/white-flag.gif" onClick="chng(this)" name="img" width="20" border="0" height="20">
</body>
</html>

Here you see that each image is idendified by a unique name for individual reference, such as 'img1,' 'imag2' and so on. What I need is to adapt a code like this but use the status of checkboxes for triggering swaps.

[edited by: incrediBILL at 11:27 pm (utc) on Aug 18, 2013]
[edit reason] URls removed. Please see forum charter and TOS [/edit]

icon_kid

5:50 pm on Aug 18, 2013 (gmt 0)

10+ Year Member



I haven't gotten much help from this forum so far on multiple image swaps but I'll try once more before seeking help at the other webmaster forums.

I have a script that will swap a pair of images based on the status of a check box, but what I need is to adapt it to handle multiple pairs of images. I've tried numerous variations of the code to no avail. Below is the URL to a demonstration of the code. When you click the check box for the 'Red Pair' the ghosted red dot turns into a deep red dot. The 'Green Pair' is a fake -- everything inside the dotted line is merely a singe image I placed there just for illustration.


[snip]
The basic code for the image swap looks like this:

<head>
<script type="text/javascript">
function processCheckbox(checkbox) {
if (checkbox.checked) {
image.src = "ICONS/Z-red.png";
image.onclick = enabledClick;
} else {
image.src = "ICONS/Z-red-ghosted.png";
image.onclick = null;
}
}
function enabledClick() {
alert("enabled!");
}
</script>
</head>


<body>

<form style='display:inline;' name="form-001" method="post" action="">
<input type="checkbox" onclick="processCheckbox(this);">
</form>

<img src="ICONS/Z-red-ghosted.png" id="image">

</body>


How do I adapt this code for both the 'Red Pair' and the 'Green Pair' of images?

[edited by: phranque at 12:16 am (utc) on Aug 19, 2013]
[edit reason] URls removed. Please see forum charter and TOS [/edit]