By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

delete some checkbox rows while click the delete button

P: 29
Hi

I have one table, in that contain deletebutton and some checkboxes.How many checkbox is selected, that is delete while click the deletebutton .

Please reply urgently..........

Thank in Advance
Jun 30 '07 #1
Share this Question
Share on Google+
9 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

what have you done so far? post some code so that we may help you with your problem ... try to simplify it to let us see the particular problem you have. as far as i understand: you have a table where you have a checkbox per row ... when you hit a delete-button you want all table-rows to be deleted where the row's checkbox is checked?

kind regards ...
Jun 30 '07 #2

kovik
Expert 100+
P: 1,044
Please reply urgently..........
First and foremost, your post is no more urgent than anyone else's. Secondly, you haven't asked a question. How can we answer? @_@
Jul 1 '07 #3

P: 29
Hi,

I post my code here ,In this code I have one deletebutton, while i click the deletebutton if checkboxes is not select one alert box is display, if one or more than one checkbox is select confirm box is display that time I want click ok means that selected checkbox rows should delete.


function checkCheckboxes()
{
var e=document.getElementsByName("delId[]");
for (i=0;i<e.length;i++)
{
if (e[i].checked==true)
{

var agree=confirm('Are you sure you want to delete these email addresses?');

if (agree)

{ return true; }

else

{ return false;
}
}

}
alert('You must select an email address to delete');
return false;
}


Thanks in Advance
Jul 2 '07 #4

gits
Expert Mod 5K+
P: 5,390
hi ...

go through the code an have a look at the comments ... tell me more about your html-code (post some of it with the row you mean and the button) ... ok?

Expand|Select|Wrap|Line Numbers
  1. function checkCheckboxes() {
  2.     // gets a collection of nodes that have the name='delId[]';
  3.     var e = document.getElementsByName("delId[]");
  4.  
  5.     // now you loop through the list of nodes
  6.     for (i = 0; i < e.length; i++) {
  7.  
  8.         // everytime you find a checked-box you ask for beeing
  9.         // sure to delete
  10.         if (e[i].checked==true) {
  11.  
  12.             // when agreed the row may be deleted?
  13.             var agree = confirm('Are you sure ...');
  14.  
  15.             if (agree) {
  16.                 // here you need something to delete the row?
  17.                 // show me some html of you - you need a reference
  18.                 // to the row you want to delete ... when having a
  19.                 // look to your html-code we may help you
  20.                 return true;
  21.             } else {
  22.                 // row shouldn't be deleted
  23.                 return false;
  24.             }
  25.         }
  26.  
  27.     }
  28.  
  29.     alert('You must select an email address to delete');
  30.  
  31.     return false;
  32. }
  33.  
kind regards ...
Jul 2 '07 #5

P: 29
hi,

I post the HTML code here,


[HTML]<HTML><HEAD><TITLE>Delete</TITLE>
<SCRIPT language="Javascript">
function checkCheckboxes()
{
var e=document.getElementsByName("delId[]");
for (i=0;i<e.length;i++)
{
if (e[i].checked==true)
{

var agree=confirm('Are you sure you want to delete these email addresses?');

if (agree)

{ return true; }

else

{ return false;
}
}

}
alert('You must select an email address to delete');
return false;
}


</SCRIPT>

</HEAD>
<BODY>
<FORM name="myform">
<INPUT onclick="checkCheckboxes()" type="button" value="Delete"><BR>
<TABLE id="tblSample">
<TBODY>
<TR id="d1">
<TD><INPUT id="delId[]" type="checkbox"> a <SPAN style="MARGIN-LEFT: 250px">Edit
</A>|Delete<BR></SPAN>
</TD></TR>
<TR id="d2">
<TD><INPUT id="delId[]" type="checkbox"> b <SPAN style="MARGIN-LEFT: 250px">Edit
</A>| Delete<BR></SPAN>
</TD></TR>
<TR id="d3">
<TD><INPUT id="delId[]" type="checkbox"> c <SPAN style="MARGIN-LEFT: 250px">Edit
</A>| Delete<BR></SPAN>
</TD></TR>
<TR id="d4">
<TD><INPUT id="list1" type="checkbox"> d <SPAN style="MARGIN-LEFT: 250px">Edit
</A>|Delete<BR></SPAN>
</TD></TR>
</TBODY></TABLE></FORM></BODY></HTML>
[/HTML]Please post using code tags - moderator
Thanks in Advance
Jul 2 '07 #6

gits
Expert Mod 5K+
P: 5,390
have a look at the following example ... i adapted it note the following things with it:

- you use getElementsByName so set the name not id
- declare i in the for loop
- have a look how to remove the line
- please write all tagnames in lowercase (the same for style-properties) ... i didn't adapt that

[HTML]<html>
<TITLE>Delete</TITLE>

<SCRIPT language="Javascript">
function checkCheckboxes() {
var e = document.getElementsByName("delId");

for (var i = 0; i < e.length; i++) {
var c_box = e[i];

if (c_box.checked == true) {

var message = 'Are you sure you want to delete?';

if (window.confirm(message)) {
var row = c_box.parentNode;
var tb = row.parentNode;
tb.removeChild(row);
return true;
} else {
return false;
}
}

}

alert('You must select an email address to delete');
return false;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="myform">
<INPUT onclick="checkCheckboxes()" type="button" value="Delete"><BR>
<TABLE id="tblSample">
<TBODY>
<TR id="d1">
<TD><INPUT name="delId" type="checkbox"> a <SPAN style="MARGIN-LEFT: 250px">Edit
</A>|Delete<BR></SPAN>

</TD></TR>
<TR id="d2">
<TD><INPUT name="delId" type="checkbox"> b <SPAN style="MARGIN-LEFT: 250px">Edit
</A>| Delete<BR></SPAN>
</TD></TR>
<TR id="d3">
<TD><INPUT name="delId" type="checkbox"> c <SPAN style="MARGIN-LEFT: 250px">Edit
</A>| Delete<BR></SPAN>

</TD></TR>
<TR id="d4">
<TD><INPUT name="list1" type="checkbox"> d <SPAN style="MARGIN-LEFT: 250px">Edit
</A>|Delete<BR></SPAN>
</TD></TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>
[/HTML]
kind regards ...
Jul 2 '07 #7

P: 29
hi,

Thankyou very much for your solution, but it support to delete one row alone, if I select more than one checkbox rows, it does not support, it support to delete first selected checkbox row.
So please give the solution.

Thanks in Advance.
Jul 3 '07 #8

gits
Expert Mod 5K+
P: 5,390
;) hey ... i adapted your code to make it work ;)) ... since it didn't work at all ... so have a close look at the code and try to adapt it for yourself first ... when you got questions ... come back and i will be glad to help you out ...

hint: if something is to delete e.length > 0 with checked boxes in respect, don't use the confirm within the loop, don't return out of the function during the remove-operation ...

kind regards
Jul 3 '07 #9

gits
Expert Mod 5K+
P: 5,390
... hmmm ... had a little time ;)

have a look at the following function that may replace the above one:

Expand|Select|Wrap|Line Numbers
  1. function checkCheckboxes() {
  2.     var e = document.getElementsByName("delId");
  3.     var message  = 'Are you sure you want to delete?';
  4.     var row_list = {length: 0};
  5.  
  6.     for (var i = 0; i < e.length; i++) {
  7.         var c_box = e[i];
  8.  
  9.         if (c_box.checked == true) {
  10.             row_list.length++;
  11.  
  12.             row_list[i] = {};
  13.             row_list[i].row = c_box.parentNode.parentNode;
  14.             row_list[i].tb  = row_list[i].row.parentNode;
  15.         }
  16.     }
  17.  
  18.     if (row_list.length > 0 && window.confirm(message)) {
  19.         for (i in row_list) {
  20.             if (i == 'length') {
  21.                 continue;
  22.             }
  23.  
  24.             var r = row_list[i];
  25.             r.tb.removeChild(r.row);
  26.         }
  27.     } else if (row_list.length == 0) {
  28.         alert('You must select an email address to delete');
  29.     }
  30. }
  31.  
but the next time ... try something for yourself first!

kind regards ...
Jul 3 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.