Forum Moderators: open
javascript would look something like
function checkit(cbox)
{
var source=(cbox.checked)? "checked.gif":"notchecked.gif";var imgs=cbox.parentNode.getElementsByTagName("IMG");
for (var n=0;n<imgs.length;n++)
if (imgs[n].className=="cbimg")
imgs[n].src=source;
}
HTML bit would look something like:
<form >
<input type="checkbox" onchange="checkit(this)">
<img class="cbimg">
</form >
You could also simplify the HTML by using the window.onload function to attach the event handler (thus the checkbox element would intrinsically pass a pointer to itself.)
I won't bother doing that here though as that would make it luverly job (and you already have one of those :-)
<script language="JavaScript">
<!--
function toggle(target)
{
obj=(document.all)? document.all[target] : document.getElementById(target);
obj.style.display=(obj.style.display=='none')? 'inline' : 'none';
}
//-->
</script>
I simply set the Tick Image for the CHECKED box to be displayed or hidden (via css) when the page is loaded (these decisions are done via php) then use the status of the checkbox to alter its display.
WITH this in the IMG tag
<img src="tickIcon.gif" border="0" alt="" id="header" style="display:none;" />
And this as the checkbox
To switch the image as required.
<input type="checkbox" name="headerlink" id="headerlink" value="1" style="border: none; vertical-align: middle;" onClick="toggle('header')" />
This should load the image displayed as none via css, then on setting the CHECKBOX it should show the image.
Use different id names for multiple objects.
Should work with all recent browser versions (windows) not sure about linux however mozilla based browsers should be fine. Mac? You tell me, im buying a G3 powerbook soon for testing so maybe ill add a post then.
Copy this post, paste it into a new html document and test it out, this could be used for other things than images.
Hopefully aswith the previous suggestion this will be of use to someone.