0

I am using the following code to make a custom checkbox with my own images.

First I included JQuery and added the JQuery code for the required functionality:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
 $(document).ready(function(){

$("#moreinfo").change(function() {
   if(this.checked) {
       $(this).prev().attr("src", "checkbox_unchecked.gif");
   } else {
       $(this).prev().attr("src", "checkbox_checked.gif");
   }
});

 });

</script>


Next...here's the HTML:



 <label for="moreinfo">
    <img src="checkbox_unchecked.gif"/>
    <input name="moreinfo" type="checkbox" id="moreinfo" style="display:none">
    </label>

The unchecked image is there but when I click on it, it doesn't change/toggle.

I'm I missing something?

UPDATE:

Testing this full code locally and it's not working...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
 $(document).ready(function(){

$("#moreinfo").change(function() {
   if(this.checked) {
       $(this).prev().attr("src", "http://icdn.pro/images/en/v/e/verify-correct-icone-9268-48.png");
   } else {
       $(this).prev().attr("src", "http://www.theology.edu/Remata/Android/Help/wrongx_icon.png");
   }
});


 });

</script>

</title>




</head>
<body>



<label for="moreinfo">
    <img src="http://www.theology.edu/Remata/Android/Help/wrongx_icon.png"/>
    <input name="moreinfo" type="checkbox" id="moreinfo" style="display:none">
    </label>




</body>
</html>

2 Answers 2

1

It's working, you can check it here.

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

2 Comments

I agree it's working there but see the full code above which I'm testing. Try it...it won't work for some reason :o/
It's not working because you wrote script codes into title tags.
0
      $("#moreinfo").click(function() {
       var $img =  $(this).prev();
$img.attr("src", ($(this).checked)?"checkbox_checked.gif":"checkbox_unchecked.gif");

    });

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.