Page 1 of 1

Using images for checkboxes

Posted: Sat Apr 17, 2004 8:12 pm
by phice
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.

Posted: Sat Apr 17, 2004 8:34 pm
by feyd

Code: Select all

function check(name)
{
  var v = document.forms&#1111;<?= $formName ?>]&#1111;name]value = parseInt(document.forms&#1111;$formName]&#1111;name]value) ^ 1;
  document.images&#1111;name].src = (v?('on'):('off'))+'.gif';
&#125;
-----------
<input type=hidden name="<?= $name ?>" value="0"><a onclick="check(this.name)" name="<?= $name ?>"><img src="off.gif" name="<?= $name ?>" /></a>
I don't have time to check it, but the logic is there. The $name's all need to be unique.

Posted: Sun Apr 18, 2004 2:10 am
by phice
It doesn't seem to be working.

I'm trying to get this to work with multiple checkboxes with the name "thread[]".

Posted: Sun Apr 18, 2004 3:24 am
by feyd
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)
&#123;
  return ((document.getElementById)?(document.getElementById(id)):(document.all&#1111;id]));
&#125;

function check(id) 
&#123;
  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'; 
&#125; 
----------- 
<input type=hidden id="<?= $id ?>" name="thread&#1111;]" value="0"><a onclick="check('<?= $id ?>_i')"><img src="off.gif" id="<?= $id ?>_i" /></a>