Log in

View Full Version : Checkbox and Images...



vbjohn
01-18-2010, 05:51 PM
Where can I find a script that would allow when someone hits a checkbox that an image that is associated with that checkbox appear in my <div> area?

djr33
01-18-2010, 09:01 PM
This is basically the same as a mouseover/rollover image script.

The action of a rollover image is based on the "onmouseover" property of an img tag:
<img onmouseover=".....">

For this, you want a similar property, that happens to be somewhere else on the page:
<input type="checkbox" oncheck="...">

The problem is that oncheck does not exist:
So, you will need to fake it. There are two ways:
--For both, you will need to use the property this.checked to see if it is checked (as opposed to unchecked):
if (this.checked) { dothis(); }
1. onclick: this works, but it triggers BEFORE the value is actually changed. So if you use onclick, you will need to find the opposite value for this.checked-- if !(this.checked) (because it has not switched yet).
2. or, slightly simpler, onchange, then it would have already changed the value, so just if (this.checked)

I think onclick will be a more immediate reaction, probably what you want.

So, it should be roughly equivalent to:
<input type="checkbox" onclick="if (!(this.checked)) { dothis(); }">
Where "dothis();" is the same action as the rollover image in the normal script.



http://www.webdeveloper.com/forum/archive/index.php/t-40285.html

That's some more relevant info if you want to look through it.

I'm not sure what the best, most reliable approach is, though.