Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic check boxes

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
i am making a site whereby on some news forum page there is the ability to add attachments to messages. While it is a simple case of getting the already attached files from some list saved in the page context to show the check boxes, how would i go about having a remove attachment button which when clicked would remove the selected attachments.

regards
cajchris
 
I would have a checkbox next to each file input, and server-side, if any checkboxes are checked, then don't upload the relevant file (or, if already uploaded, delete it).

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If your files are being shown as checkboxes (or you have a checkbox next to a filename - you're not too clear on this point), something like this:

File1.jpg X
File2.jpg X
etc

then when the form is submitted, simply see which checkboxes are checked, and remove the relevant files.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
OK - let me try some more...

You are presumably submitting the form with checkboxes back to a server-side page. On this page, presumably you also know how to find out details of the posted form elements (how have you managed the file uploads otherwise?)

So... loop around all the checkboxes that relate to the attachments you wish to delete, and any that are checked, then delete the attachment that goes with it.

I'm not sure I can explain it any simpler than I have already... so maybe asking in a server-side forum would be more appropriate if you are having difficulty implementing that side of things.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
i am using a jsp page to do this. And yes i do know the details of the posted form elements. But without using javascript how do i loop around these checkboxes and remove them, and the files themselves.
 
You can do it client-side with javascript as a normal course of business. It is not out-of-order.
[tt]
<html>
<head>
<script language="javascript">
var ormv;
function deleteit() {
var oelem=document.forms[0].elements["cb1"];
ormv=oelem.parentNode.removeChild(oelem);
}
function reinsertit() {
if (ormv) {
var oelem=document.getElementById("divid");
oelem.appendChild(ormv);
ormv=null;
}
}
</script>
</head>
<body>
<form>
<div id="divid">cb1:<input type="checkbox" name="cb1" value="cb1" /></div>
<div id="divid2">cb2:<input type="checkbox" name="cb2" value="cb2" /></div>
</form>
<button onclick="deleteit()">delete a checkbox cb1</button><br />
<button onclick="reinsertit()">re-insert the checkbox cb1</button><br />
</body>
</html>
[/tt]
Div's there are to make life slightly easier for this specific case of reinsertion. It is not generic requirement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top