/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@mavigozlerMar 19.2010 — 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>
[code=php]<?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";
?>[/code]

</body>

</html>
=============================



This should guarantee that the choices are not included in the HTML of the served document.
Copy linkTweet thisAlerts:
@Marchingknight1authorMar 19.2010 — 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".
Copy linkTweet thisAlerts:
@mavigozlerMar 19.2010 — 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.
Copy linkTweet thisAlerts:
@Marchingknight1authorMar 19.2010 — alternatively, it would be fine if each box had its own remove link, like below

[]A [U][COLOR="Blue"]remove[/COLOR][/U]

[]B [U][COLOR="blue"]remove[/COLOR][/U]

[]C [U][COLOR="blue"]remove[/COLOR][/U]
Copy linkTweet thisAlerts:
@Marchingknight1authorMar 19.2010 — 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.
Copy linkTweet thisAlerts:
@mavigozlerMar 19.2010 — You want some kind of persistence. An alternative is to set cookies to indicate the user's status then.
Copy linkTweet thisAlerts:
@Marchingknight1authorMar 19.2010 — 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?
Copy linkTweet thisAlerts:
@Marchingknight1authorMar 19.2010 — could something along the lines of the following script be used to perform the permanent removal?

[code=php]<?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");
}
?>[/code]
Copy linkTweet thisAlerts:
@mavigozlerMar 19.2010 — 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? [/QUOTE]


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().
Copy linkTweet thisAlerts:
@tirnaMar 19.2010 — 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

[URL]http://www.webdeveloper.com/forum/showthread.php?p=1076016#post1076016[/URL]
×

Success!

Help @Marchingknight1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...