I'm looking for something easy to use to allow my application to use images as checkboxes (on.gif and off.gif) instead of normal checkboxes.
Thanks guys.
Using images for checkboxes
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
function check(name)
{
var v = document.formsї<?= $formName ?>]їname]value = parseInt(document.formsї$formName]їname]value) ^ 1;
document.imagesїname].src = (v?('on'):('off'))+'.gif';
}
-----------
<input type=hidden name="<?= $name ?>" value="0"><a onclick="check(this.name)" name="<?= $name ?>"><img src="off.gif" name="<?= $name ?>" /></a>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
the way this works is based off the name. One could switch it to using id's pretty easy...
Code: Select all
function getElem(id)
{
return ((document.getElementById)?(document.getElementById(id)):(document.allїid]));
}
function check(id)
{
var o = getElem(id);
var i = getElem(id+'_i');
if(!o || !i) return false;
var v = o.value = (parseInt(o.value)?(0):(1));
i.src = (v?('on'):('off'))+'.gif';
}
-----------
<input type=hidden id="<?= $id ?>" name="threadї]" value="0"><a onclick="check('<?= $id ?>_i')"><img src="off.gif" id="<?= $id ?>_i" /></a>