Accessing checkbox without submitting

Hey

Does anyone know how I can access a check box without submitting through a form or where I can get info to this effect?
I want to build an array where if the check box in a table is marked, the array is filled with 1 and if the check box is left blank the array is filled with 0.

Any assistance is appreciated.

What array? php array or javascript array?

I want to fill a PHP array…

This is the code with the a comment of what I’d like to do but I’m not sure how to do it or if it can be done


<form action=client_update_comm.php method=post>
<table align=center bordercolor=black cellpadding=10 cellspacing=0 border=1 borderwidth=0>
<tr>

<td>Client</td>
<td>End Imm</td>

<tr>
<?
$query="SELECT * FROM comm_SalesStaffDetails WHERE ClientKey = '$clientkey' and Active = 'Y'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;

if($num == 0){
      $skey=mysql_result($result,$i,"SalesStaffKey");
?>
      <td><input type="hidden" name="staffkey[]" value="<? echo $staffkey ?>"><? echo $salesname ?> <? echo $salessurname ?> </td>
     <td align=center><input type="checkbox" name="endimmed" value="checkbox">
     </td>
     <?
     /*This is where I want to access the value of the check box before the submit button is clicked.
      Checked = 1
      Unchecked = 0
      load into PHP array
      pass using the form and submit button
      Load into text field <input type="hidden" name="xxxxxxx" value="<?  echo $phparray?>" >
*/
?>

   </tr>
<?
$i++;
}
?>
<td colspan=9 align=center><input type=submit value="Submit"></td>
</table>
</form>

If there is a way to accomplish this, I would greatly appreciate any assistance.

I think this can only be done through javascript…

Try adding id’s to your checkboxes and access them through that…

hope this gave you an idea…
i’m not really good w/ javascript so i cant really show you how… hehehe

What exactly do you need to do?
You know you need to send the checkbox value to the server somehow. If you don’t want to actually have a form with a submit button, then you need to use ajax to send checkbox value every time someone checks on unchecks that checkbox

You cannot access any form value with PHP before submitting the form. PHP is server side, the checkbox values before form submission resides in the browser memory and PHP has nothing to do with it. Only after submission php can parse, validate and eventually save form data. So you will need javascript without any doubt.

This is what I need to do…

1 - I need to get information from a database using a mySQL query.
2 - The data will vary in the amount of records, one query could return 1000 record, another could return only 4/5.
3 - The records need to be displayed to the user in HTML table (within HTML form)
4 - The user will be able to enter information in a text input area
5 - The user will be able to check a checkbox if necessary indicating a YES/NO option
6 - The user clicks submit and the information is written to database table.

I’m saying this upfront - I am not good with arrays but I have tried to use them to fix this problem.
Solutions I have tried:
a) I thought of making each line an array and passing that but I’m not sure how to create that kind of array and display the information in a table for the user to display.
b) I tried passing each field as an individual array but the check box will only pass the exact number of boxes that are checked (i.e if 6 records are returned and the user checks only 1 box, the checkbox array will have only 1 record)
c) I have attempted to find a way to get checkbox info out before submit which I have found out cannot be done - thanks guys.

I’m totally out of ideas now so if anyone has any ideas on how I can get the above “To Do” steps to work, I am open to all suggestions

I assume you have to choose either yes or no, ie not choosing yes means no and vice versa? in which case can you just use radio with a default selected to ensure you get a result for every record?

<input type="hidden" name="checkboxes[0]" value = "no">
<input type="checkbox"  name="checkboxes[0]" value = "yes">
<input type="hidden" name="checkboxes[1]" value = "no">
<input type="checkbox"  name="checkboxes[1]" value = "yes">
<input type="hidden" name="checkboxes[2]" value = "no">
<input type="checkbox"  name="checkboxes[2]" value = "yes">

If you code your checkboxes in the HTML like this then it will send the results to the server as an array with “yes” for the checkboxes that are checked and “no” for the checkboxes that are not checked.

First you said you need to access the checkbox data without submitting, not it becomes apparant that you will be submitting the form to the server.

Now your requirements are different and actually much easier, since now it’s just a plain html form. There is really nothing special about it, you are basically asking how to create an html form using the data from a database.

I just worked on this recently with the help of SP only. :slight_smile:

Check this thread. you can store whatever you want when check box is marked or unmarked.