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