www.webdeveloper.com
Results 1 to 11 of 11

Thread: removing html checkboxes

  1. #1
    Join Date
    Mar 2010
    Posts
    28

    removing html checkboxes

    I have a checkbox list and I need to be able to dynamically remove a box from the list. More importantly, I need to have it permanently removed from the html file, so that the next time any user opens the page, a checkbox that has been previously removed will not show up.

    I can write a script to remove it from the page, but the next time I load the page, the original list will still be there.

    An example of what I need to do is below

    I have this page:

    [x] A
    [ ] B
    [x] C

    {delete checked}

    when the delete checked button is clicked, the A and C checkbox will be removed, and I'll be left with the following:

    [ ]B

    {delete checked}

    However, the next time the page is loaded, I need the 2nd page to show up, not the first.

    Thanks

  2. #2
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    Using Javascript, you hide the checkboxes, right?

    Within a <form> element, create <input> elements of type "hidden" and set 'name' and 'value' attributes. Your Javascript will set the value of the hidden inputs when the checkbox is set or unset (you might use the values of the checkbox "true" or "false").

    When user requests the next page (re-load?), you must make sure the request is in a form submission: action="yourURL.php" method="get"

    On the server side, you use PHP for retrieving $_GET['name'] form values, which indicate which checkboxes were "deleted".

    Your 'yourURL.php' document should look something like this:

    ============================
    <!DOCTYPE....use Strict HTML
    <html>...
    .
    .
    .
    <body>
    PHP Code:
    <?php
       
    if ($_GET['chboxA'] != 'unset')
          echo 
    "<input type=\"checkbox\" name=...> A";
       if (
    $_GET['chboxB'] != 'unset')
          echo 
    "<input type=\"checkbox\" name=...> B";
       if (
    $_GET['chboxC'] != 'unset')
          echo 
    "<input type=\"checkbox\" name=...> C";
    ?>
    </body>
    </html>
    =============================

    This should guarantee that the choices are not included in the HTML of the served document.
    Last edited by mavigozler; 03-19-2010 at 10:43 AM.

  3. #3
    Join Date
    Mar 2010
    Posts
    28
    Mavigozler, thanks for responding

    The problem with this is that I already have a submit button set to run a separate script in another php file (lets say Tool.php), so my form submission is action="Tool.php" method="post". I can't change this, because then the tool will no longer do what it needs to. Unless I can have multiple submit button that use different form elements (which I didn't think i could), then I wouldn't be able to do it this way. It would need to be done with a separate input type="button".

  4. #4
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    You are saying that the next page to be served to the client (user) is not necessarily the same page with the form containing the checkboxes, but that it could be several pages later or even different days, but you want to remember what the user did so that any future serving of the page with the checkboxes is properly modified.

    Well, in that case, you need to store the user's settings on these checkboxes in a database, and then before that page of checkboxes is served to the user, you must identify the user and then check the database record on that user as to what his settings are. You would then serve the page with the checkboxes present or absent, based on what you found in the database record.

  5. #5
    Join Date
    Mar 2010
    Posts
    28
    alternatively, it would be fine if each box had its own remove link, like below

    []A remove
    []B remove
    []C remove

  6. #6
    Join Date
    Mar 2010
    Posts
    28
    well its an admin process being developed, so ideally when anyone changes the page, the actual html page should be altered permanently.

    Also, there is no database currently in use for this tool and I'd rather not have to set one up for such a small feature unless I really have to.

  7. #7
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    You want some kind of persistence. An alternative is to set cookies to indicate the user's status then.

  8. #8
    Join Date
    Mar 2010
    Posts
    28
    the problem with cookies is that the administrator would have to log in from the same computer every time. the point is that person A deletes a checkbox from the page from a computer in London, and 5 minutes later person B logs in from Tokyo and the checkbox should still be deleted.

    Are you saying that there is no way to do this without a database?

  9. #9
    Join Date
    Mar 2010
    Posts
    28
    could something along the lines of the following script be used to perform the permanent removal?

    PHP Code:
    <?php
    function remove($var){
        
    $doc = new DOMDocument();
        
    $doc loadHTMLFile("file.html");
        
        
    $formList $doc->getElementsByTagName('form');
        
    $form $formList->item(0);
        
        
    $removalNode null;
        
        for (
    $i=0;$i<$form->length;$i++){
            if(
    $form->item($i)->nodeValue == $var){
                
    $removalNode=$form->item($i);
                break;
            }
        }
        
        
    $form->removeChild($removalNode);
        
        
    $doc->saveHTMLFile("file.html");
    }
    ?>

  10. #10
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    the problem with cookies is that the administrator would have to log in from the same computer every time. the point is that person A deletes a checkbox from the page from a computer in London, and 5 minutes later person B logs in from Tokyo and the checkbox should still be deleted.

    Are you saying that there is no way to do this without a database?
    Yes.

    If several users from different hosts are affecting the HTML document structure by their inputs, and the document is to be modified based on those inputs, then yes, the server has to keep track of this. It can keep a record in a file, or in its memory, or it can work with a database.

    And if several users can affect the status/structure of the HTML document, then you also need to worry about locking out the serving the document to user B if user A just requested it and is making changes that could create a confusing state of the document. This too is a problem with databases where two users try to write/update/change the same record in different ways (concurrency problem).

    As to your follow-up, while you can use DOM Document class methods in PHP to manipulate an HTML file for output (why?), think about where the value of parameter $var comes from for the call to remove().

  11. #11
    Join Date
    Mar 2010
    Posts
    2,803
    This appears to be the same thread as in the Javascript forum

    It looks to me you need a database as I described in the other thread before I stumbled across this one

    http://www.webdeveloper.com/forum/sh...16#post1076016

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles