This is a discussion on Storing checkbox selections between record paging within the PHP Language forums, part of the PHP Programming Forums category; Reposted (not sure if got sent) I have results being displayed each with its own checkbox name "selected[]" ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Reposted (not sure if got sent)
I have results being displayed each with its own checkbox name "selected[]" and value "id". When someone checks a checkbox, and then continues to page through the data (mysql select), I want that checkbox to be remembered. Basically I want the user to have multiple selections of checkboxes when paging through data (recordset), then they click a "continue" button, it takes all those values which are checked (over all the pages) and does its thing (insert into a database). One way I thought of is a JavaScript onClick each time a checkbox is ticked, it adds it to an array, then uncheck would delete it from that array. I'm just not sure how I'd get that javascript array through to PHP. It sounds overly complicated. Another way is running a query every time a page is loaded. So on the pageing buttons, I force the form to submit each time, writing that pages data into a PHP $_SESSION array. But I dont know how to differentiate when the page buttons are submitting the form or when the button is submitting the form, and I figured there must be an easier way. Kind regards |
|
|||
|
RelaxoRy wrote:
> Reposted (not sure if got sent) > > > I have results being displayed each with its own checkbox name > "selected[]" and value "id". > > When someone checks a checkbox, and then continues to page through the > data (mysql select), I want that checkbox to be remembered. Basically > I want the user to have multiple selections of checkboxes when paging > through data (recordset), then they click a "continue" button, it > takes all those values which are checked (over all the pages) and does > its thing (insert into a database). > > One way I thought of is a JavaScript onClick each time a checkbox is > ticked, it adds it to an array, then uncheck would delete it from that > array. I'm just not sure how I'd get that javascript array through to > PHP. It sounds overly complicated. http://mickweb.com/javascript/forms/...kboxArray.html <script type="text/JavaScript"> onload= function(){ var d=document.forms[0],w=d.length; while(w--){ if(d[w].type=="checkbox"){ d[w].onclick=function(){ var f=this.form,x=f.length,temp=[]; while(x--){ if(f[x].type=="checkbox" && f[x].checked){ temp.push(f[x].value); } } this.form.hiddenFieldName.value=temp.join(","); } } } } </script> This will be available to your parsing document as comma delimited string. Mick > > Another way is running a query every time a page is loaded. So on the > pageing buttons, I force the form to submit each time, writing that > pages data into a PHP $_SESSION array. But I dont know how to > differentiate when the page buttons are submitting the form or when > the button is submitting the form, and I figured there must be an > easier way. > > Kind regards |