how to delete a file using checkbox!!!
i'm developing one project using the file operations implementations. I'm displaying the contents of the file in my jsp page. The first column i've putted a checkbox option and at last i've created the button. If i clicked that particular checkbox and then if i press the delete button then it should be able to delete the all check marked files from the directories.
Could anyone tell me how to do this in jsp. Is there any need for javascript or it can be done only through the jsp codings.
in advance thanks....
> i'm developing one project using the file operations
> implementations. I'm displaying the contents of the
> file in my jsp page. The first column i've putted a
> checkbox option and at last i've created the button.
> If i clicked that particular checkbox and then if i
> press the delete button then it should be able to
> delete the all check marked files from the
> directories.
> Could anyone tell me how to do this in jsp. Is there
> any need for javascript or it can be done only
> through the jsp codings.
> in advance thanks....
Use a flag called delete.Whenever you want to select a checkbox then delete should be set to true.If selecting the check box is followed by the click of the button to delete then that will generate a ActionEvent which you will receive using the Listener where you can check the value of delete flag which if its true indicates that files have been selected and you can continue deleting.If delete flag is false then you can pop a message saying no files have been selected.This selection procedure can used to perform other actions than deleting too.
[nobr]<html>
<head>
<title>Delete All Example</title>
<script>
function DeleteAll(){
var answer = confirm("Do you really want to delete these selected files?")
if (answer != 0) {
for(var i=0; i<3; i++){
if( (document.form1.filecheck(i).checked == true) && (document.form1.filepath(i).value != "") ){
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
fso.DeleteFile(document.form1.filepath(i).value, true);
}
}
}
}
</script>
<body>
<form name="form1">
<table border="1">
<script>
for(var i=0; i<3; i++){
document.write("<tr><td><input type='checkbox' name='filecheck' value='filecheck'><br></td><td><input type='file' name='filepath'></td></tr>")
}
</script>
<tr><td colspan="2" align="center"><input type="button" name="go" value="Delete All" onClick="DeleteAll()"></td></tr>
</table>
</form>
</body>
</html>
Cheers[/nobr]
thanks for this code .., but this is not deleting the files. Also tell me how to use this code in the way, that it first check the checkbox that how many are checked and then only it delete the corresponding files.Message was edited by: Navneet_Singh
> thanks for this code .., but this is not deleting the
> files. Also tell me how to use this code in the way,
> that it first check the checkbox that how many are
> checked and then only it delete the corresponding
> files.
>
> Message was edited by:
> Navneet_Singh
Hello Navneet, I gave u the full code. U can make slight changes and meet ur requirement. This is not a forum to spoon feed. Then also I gave u the full code and u r not able to change it according to ur req. This code is working fine in my system. I dont know whats the problem with ur system. What OS u r using and what js error message u got?