pioneerx01 Posted August 21, 2013 Share Posted August 21, 2013 Hi, I have this html (PHP) code running in a loop 10 times or so for different vendors: $row_count = 0; foreach ($vendors_array as $vendor) { echo "<div class=squaredTwo>"; echo "<input type='checkbox' value='$row_count' id='squaredTwo' name='$row_count' />"; echo "<label for='squaredTwo'></label>"; echo "</div>"; echo "<div style='float:left; font-size:17px; padding-left:20px; margin-top:-28px; '> $vendor </div>"; $row_count = $row_count + 1; } This yields a list of vendors with checkbox next to it. However no matter what checkbox I click only the first one toggles. I have found the CSS code online, and it is a little bit advanced for me, so I am not sure what exacly is going on. Any help would be appreciated. input[type=checkbox] { visibility: hidden; } /* SQUARED TWO */ .squaredTwo { width: 28px; height: 28px; background: #fcfff4; /* background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 ); margin: 0px 0px 4px 0px; -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); position: relative; } .squaredTwo label { cursor: pointer; position: absolute; width: 20px; height: 20px; left: 4px; top: 4px; -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); background: -moz-linear-gradient(top, #222 0%, #45484d 100%); background: -o-linear-gradient(top, #222 0%, #45484d 100%); background: -ms-linear-gradient(top, #222 0%, #45484d 100%); background: linear-gradient(top, #222 0%, #45484d 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#222', endColorstr='#45484d',GradientType=0 ); } .squaredTwo label:after { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); opacity: 0; content: ''; position: absolute; width: 9px; height: 5px; background: transparent; top: 4px; left: 4px; border: 3px solid #fcfff4; border-top: none; border-right: none; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); } .squaredTwo label:hover::after { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; filter: alpha(opacity=30); opacity: 0.3; } .squaredTwo input[type=checkbox]:checked + label:after { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter: alpha(opacity=100); opacity: 1; } Quote Link to comment https://forums.phpfreaks.com/topic/281440-problem-with-checkbox-css/ Share on other sites More sharing options...
kicken Posted August 21, 2013 Share Posted August 21, 2013 Every checkbox needs to have it's own ID. Right now they are all set to id="squaredTwo" which is invalid as an ID must be unique throughout the entire HTML document. The browser will keep the first instance of that ID, and ignore every other one. Quote Link to comment https://forums.phpfreaks.com/topic/281440-problem-with-checkbox-css/#findComment-1446181 Share on other sites More sharing options...
pioneerx01 Posted August 21, 2013 Author Share Posted August 21, 2013 (edited) Oh, how lovely Do you know of a quick and easy way of getting arround it? I can think of few, but non seem "correct" or "easy" enough Thanks Edited August 21, 2013 by pioneerx01 Quote Link to comment https://forums.phpfreaks.com/topic/281440-problem-with-checkbox-css/#findComment-1446191 Share on other sites More sharing options...
kicken Posted August 21, 2013 Share Posted August 21, 2013 Just use your $row_count variable as part of the ID. id='vendor_{$row_count}'Change the label's for attribute to match whatever ID you use. Quote Link to comment https://forums.phpfreaks.com/topic/281440-problem-with-checkbox-css/#findComment-1446192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.