1

Is there a way that I can have an image replace a checkbox, and when someone clicks on it, it selects it, and changes the image to another image like a "checked" image?

So essentially:

[heart-icon] Health and Fitness

user clicks on it

[check-icon] Health and Fitness

and now that area is selected

1

3 Answers 3

3

There are definitely scripts/plugins available to do this. I've not used any of them so I can't recommend one specifically, but here's an example:

http://www.itsalif.info/content/ezmark-jquery-checkbox-radiobutton-plugin

Sign up to request clarification or add additional context in comments.

1 Comment

2

I would try this plugin: SimpleImageCheck http://www.jkdesign.org/imagecheck/

Code to customize the checkbox looks simple:

$('#checkbox').simpleImageCheck({
  image: 'unchecked.png',
  imageChecked: 'check.png'
  afterCheck: function(isChecked) {
    if (isChecked) {
      // do something
    }
  }
});

1 Comment

This is amazing! Exactly what I was looking for. Thanks!! How would I go about adding multiple icons instead of one static unchecked.png, say I want like 16 different icons and have them all change to the check.png after clicking?
0

No need of plugins nor JQuery:

<span onclick="changeCheck(this)">
<img src="http://www.clker.com/cliparts/e/q/p/N/s/G/checkbox-unchecked-md.png">
<img src="http://www.clker.com/cliparts/4/h/F/B/m/4/nxt-checkbox-checked-ok-md.png">
<input type="checkbox" name="chk">
</span>
<script>
function changeCheck(target)
{
    chk = target.lastElementChild;
    chk.checked = !chk.checked;
    target.children[+ chk.checked].style.display = '';
    target.children[1 - (+ chk.checked)].style.display = 'none';
}
function initCheck()
{
    chk = document.getElementsByName('chk')[0];
    chk.style.display = 'none';
    chk.parentNode.children[1 - (+ chk.checked)].style.display = 'none';
}
initCheck();
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.