troubleshooting Question

Change static entered data to dynamic with counter

Avatar of Jazzy 1012
Jazzy 1012 asked on
CSSPHPHTML
5 Comments1 Solution129 ViewsLast Modified:
I have this code:
<?php if($dayt == '1'){  }?>
      </td>
      <td>
      <center>
      <input type="checkbox" class="colour-button cbb" name="v1" value="10 - 12" id="btn1012" /><label for="btn1012"> <i class="fa fa-check-circle hide12" id="chk-btn1012"></i>  <?php echo $dayt?></label>
      <input type="checkbox" class="colour-button cbb" name="v1" value="10 - 12" id="btn1214" /><label for="btn1214" class="labe"><i class="fa fa-check-circle hide12" id="chk-btn1214"></i> <?php echo $row3[10]?></label>
      </center>
      </td>
      <td>
              <?php }?>
      
      </td>
            <td>
            <center>
      <input type="checkbox" class="colour-button cbb22" name="v2" value="10 - 12" id="btn10" /><label for="btn10"><i class="fa fa-check-circle hide13" id="chk-btn10"></i>  10am - 12pm</label>
        <input type="checkbox" class="colour-button cbb22" name="v2" value="10 - 12" id="btn12" /><label for="btn12" class="labe"><i class="fa fa-check-circle hide13"  id="chk-btn12"></i>  5pm - 7pm</label>
      </center>

Open in new window


And this is the Javascript I have:
<script>
$(function() {
	  $(".colour-button").click(enable_cb);
	});
	function enable_cb() {
		   if (this.checked) {
		        //this will mean at least one is always checked
		        $("input.colour-button1").prop("disabled", false);
		        $("#chk-" + this.id).show();
		    }
		    else {
		        //in this case, hide the element if you need to, but check for ANY items
		        //$("input.colour-button1").attr("disabled", true);
		        $("#chk-" + this.id).hide();

		        if ($(".colour-button:checked").length == 0) {
		            $("input.colour-button1").attr("disabled", true).prop("checked", false);
		            $('.hide11').hide(); 
		        	 $('#submit').attr('disabled', true).removeClass('orangeBtn23').addClass('disabled'); //disable input
			            
		        }
		    }
		}
</script>

Open in new window


Now the first part of my code I want to change it from static to dynamic, meaning I have a query and I want my input box to be inside my while loop for it to execute a variable in each loop. My only issue here is the id "chk-btn10..." Because I have them statically now to use in my javascript, is there a way I can make my id = "chk-btn ++" that it increments everytime so I can add it statically and not ruin my javascript?

My query while loop is before the code like this:
While($row= mysqli_query_rows($result)){

//MY CODE SHOWN ABOVE


}

Open in new window

ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004