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

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.