genzedu777 Posted November 13, 2010 Share Posted November 13, 2010 Hi I need some help in jquery. Currently I am working on locations. Example, if the user were to 'checked' NORTH check box, then the DISTRICT checkboxes will be activated for checking, However if the user did not check the NORTH check box, the DISTRICT checkboxes will be deactivated and are not allowed to be check. Currently my code is not working, and I have tried to troubleshoot many times with no avail, any idea what went wrong? Thanks <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $('#zone').click(function() { //check to make sure field is checked if ($(this).attr('checked')) { $('#district input').attr('disabled', false).css('backgroundColor','#E5E5E5'); $('#district label').css('color','#CCC'); } else { $('#district input').attr('disabled', true); } }); // end click() </script> <?php /***North's DISTRICTS***/ echo '<div id="zone">'; echo '<input name="zone[]" type="checkbox" id="zone_1" value="1">'; echo '<span class="zone_text_enlarge"><label for="zone_1">North</label></span><br/>'; echo '</div>'; $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC LIMIT 7"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); echo'<div id="district">'; echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="district[]" type="checkbox" id="district_'.$data['district_id'].'" value="'.$data['district_id'].'"/>'; echo '<label for="district_'.$data['district_id'].'">'.$data['district_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table><br/><br/>'; //Close your last row and your table, outside the loop echo '</div>'; //close div = district ?> Quote Link to comment https://forums.phpfreaks.com/topic/218565-jquery-on-activating-and-deactivating-checkboxes/ Share on other sites More sharing options...
RichardRotterdam Posted November 13, 2010 Share Posted November 13, 2010 Try the code tags I'ts quite hard to read the pasted code as it is. Can you describe exactly what isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/218565-jquery-on-activating-and-deactivating-checkboxes/#findComment-1133896 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.