#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    83
    Rep Power
    11

    check checkbox and save the value as session


    Hie.. I am just wondering if it is possible for me to check a check box and save the selected check box value as session?
    Please do let me know how if it is possible.
    Thank you...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    246
    Rep Power
    11
    Code:
    <form method=post> // basic form to set $_POST[check]
    <input type=checkbox name=check[] value=$yourvalue> // creates the checkbox
    <input type=button value=Save> // simple button to send $_POST[check]
    
    if ($_POST[check]) { // if the checkbox was checked
    ... your insert/update query to save session goes here ...
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    83
    Rep Power
    11
    Appreciate that r0dn3y...
    Well.. I realized that it is possible to do it through "form method=POST"
    Mayb I should have made my question clearer...
    Well, I would like to save the selected checkboxes values. I want those values to be saved as session, so that when I move to another folder and I selected some items, I will have them all in one session.
    For example...
    PHP Code:
    I have the following items:
    1. AA/A/1A.txt
    2. AA
    /A/2A.txt
    3. BB
    /B/1B.txt 
    4. BB
    /B/2B.txt
    Submit button

    I just want to choose 1A
    .txt and 2B.txt itemsI want them to be saved as session before I click button submit
    Hope I make myself clear.. thanks..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    246
    Rep Power
    11
    It's 6AM, and I've been up wayyy too many hours. But if I understand what you're saying, the foreach statement should do your 'save' through an update, then checked name returns those selections on the following page.

    Page one (or folder one) updates with the checked values, and page two uses the updated values to apply 'checked name' so the preselected values are 'pre-checked', this would ensure the next update included the values of the previous one.
    Unsure how else you can 'save' the values without updating, that's beyond what little I know.

    Also, if you have need of it, this little javascript selects all the checkboxes on one click (I use it to allow my members to delete all PM's at once, etc etc).
    Code:
    <script language="javascript">
    function checkAll () {
    for (a=0;a<document.forms[0].elements.length;a++) {
      if (!document.forms[0].elements[a].checked) {
        document.forms[0].elements[a].checked=true;
      } else {
        document.forms[0].elements[a].checked=false;
      }
    }
    }
    </script>
    Bedtime for bonzo here, hope you get it worked out.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    83
    Rep Power
    11
    So, you mean that I need to update it? Would you please tell me further about this?
    Well, I had the code for CheckAll already. Anyway, thanks though....
    My problem is to save the selected check box item from different folders to a session and those will be sent in one click when I click submit button...
    Thanks...

IMN logo majestic logo threadwatch logo seochat tools logo