checkbox - jquery unchecked checkboxes changes images -


some details first:

i have 4 image place holders. have several checkboxes. each checkbox associated image. user allowed check off 4 boxes.

when user clicks on checkbox replaces 1 of image place holders image assoicated checkbox.

after user checks off 4 of check boxes, rest of chexkboxes become disabled.

so have 4 image place holders populated images checked check boxes.

here issue comes play.

if user decides uncheck box, need correct place holder image go it's generic place holder image.

so if 4 checkboxes user checked 1: hammer 2: screwdriver 3: nails 4: saw. 4 place holder images populated hammer, screwdrive, nails , saw. if decide uncheck screwdriver checkbox placeholder image screwdrive should switch generic place holder image.

i'm having hard time figuring out how that.

thanks in advance!

function countchecked() {        var radiocandycount = document.getelementsbyname('howmanycandies');               (var = 0, length = radiocandycount.length; < length; i++) {                 if (radiocandycount[i].checked) {                  var = radiocandycount[i].value;                 var b = "2";                 var c = number(a) + number(b);            var n = $("input:checked").length;           document.getelementbyid("candycount").value = number(c) - number(n) 

// not work ....this section revert place holder images generic image... not work

        if (document.getelementbyid("candycount").value == 4) {             $('#jar1').css("background-image", "url(/images/singlejar.png)");             $('#jar2').css("background-image", "url(/images/singlejar.png)");             $('#jar3').css("background-image", "url(/images/singlejar.png)");             $('#jar4').css("background-image", "url(/images/singlejar.png)");           }         if (document.getelementbyid("candycount").value == 3) {              if ($(this).not(':checked')) {                                  var unchecked = this.value;                                     if ($('#jar1').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                     $('#jar1').css("background-image", "url(/images/singlejar.png)");                 }                 if ($('#jar2').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                     $('#jar2').css("background-image", "url(/images/singlejar.png)");                 }                 if ($('#jar3').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                     $('#jar3').css("background-image", "url(/images/singlejar.png)");                 }             }           }         if (document.getelementbyid("candycount").value == 2) {              if ($(this).not(':checked')) {                  var unchecked = this.value;                  if ($('#jar1').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                     $('#jar1').css("background-image", "url(/images/singlejar.png)");                 }                 if ($('#jar2').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                     $('#jar2').css("background-image", "url(/images/singlejar.png)");                 }              }           }         if (document.getelementbyid("candycount").value == 1) {              if ($(this).not(':checked')) {                   var unchecked = this.value;                   if ($('#jar1').css("backgroundimage") == "url(\"/images/" + unchecked + ".png\"" + ")");                 {                                            $('#jar1').css("background-image", "url(/singlejar.png)");                 }              }           }                      // *****end**** section revert place holder images generic image *****end****                       // section changes place holder image based on associated checkbox image          if (length == 3) {             if (document.getelementbyid("candycount").value == 3) {                 $(':checkbox(:checked)')                                         if (this.checked) {                                                  var candychoice = "url(" + "/images/" + this.value + ".png )";                                                    $('#jar4').css("background-image", candychoice);                     }              }             if (document.getelementbyid("candycount").value == 2) {                 $(':checkbox(:checked)')                                     if (this.checked) {                            var candychoice = "url(" + "/images/" + this.value + ".png )";                                                     $('#jar3').css("background-image", candychoice);                     }              }             if (document.getelementbyid("candycount").value == 1) {                 $(':checkbox(:checked)')                                     if (this.checked) {                            var candychoice = "url(" + "/images/" + this.value + ".png )";                                                    $('#jar2').css("background-image", candychoice);                     }              }             if (document.getelementbyid("candycount").value == 0) {                 $(':checkbox(:checked)')                                     if (this.checked) {                            var candychoice = "url(" + "/images/" + this.value + ".png )";                                                     $('#jar1').css("background-image", candychoice);                     }              }         }                      // *****end****  section changes place holder image based on associated checkbox image  *****end****            if (n == c)                                                           {                                                                           $(':checkbox:not(:checked)').prop('disabled', true);                   document.getelementbyid('addcart').style.display = 'inline';                   $(document).scrolltop( $("#addcart").offset().top );                    $("#stepfourcheck").fadein('slow');                }                                                                  else                                                                   {                                                                    $(':checkbox:not(:checked)').prop('disabled', false);              document.getelementbyid('addcart').style.display = 'none';            document.getelementbyid('stepfourcheck').style.display = 'none';                }             }             }             } 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -