Jump to content

retrieving checkbox value within php


jerald717

Recommended Posts

Hi,

 

so i have a problem. I'm using a script to enable and disable checkboxes, and i'm id-ing them fetching values from a database:

 

while($data = mysqli_fetch_array($sql))

{

  if ($count % 5 == 0) {

    echo '</tr><tr>';

    $count = 0;

  }

  echo '<td><input name="subject_level[]" class="subject_a" disabled="disabled" type="checkbox" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>';

  echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>';

  $count++; //Increment the count

}

 

The names of the checkboxes come out fine, just that, is there any way to retrieve the values of the checkboxes into an array of some sort so that i could build a search query later?

 

if($_POST(subject_level)) or if($_POST(subject_level[]))  doesn't return true. does it make sense? im new to php so please forgive my ignorance. Help appreciated. Thanks!

 

Link to comment
Share on other sites

I see. Yea I'm using a javascript to enable or disable the checkbox. Won't the value be changed through js? The reason I'm using javascript to do that is because I want to enable/disable a group of checkboxes using one checkbox. I'll see if I can post that script up after lunch. It could help if anyone could refer me to a thread or tutorial that does this? Will need to use the Id values of the checkbox to build search queries.

Link to comment
Share on other sites

Alright, thanks man.

 

for anyone else who could help, the js script i'm using to enable/disable my checkboxes is put below. I have set the default for the checkboxes as disabled, but somehow the js doesnt seem to be enabling them. Alternatively, if anyone could refer me to a tutorial/thread which has got to do with a similar problem, let me know thanks!

 

<script type="text/javascript">

$(document).ready(function() {

 

//Level_1 and subject_a

$('label.subject_1').toggleClass('inactive');

$('#level_1').click(function() {

$('label.subject_1').toggleClass('active');

            $('.subject_a').each(function() {

               

                $(this).attr('disabled', !$(this).attr('disabled'));

                $(this).attr('checked', false);

            })

           

        });// end click()

</script>

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.