Jump to content

jquery on activating and deactivating checkboxes


genzedu777

Recommended Posts

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

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.