Using images for checkboxes

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Using images for checkboxes

Post 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.
Image Image
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

It doesn't seem to be working.

I'm trying to get this to work with multiple checkboxes with the name "thread[]".
Image Image
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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>
Post Reply