Current location: Hot Scripts Forums » General Web Coding » JavaScript » Delete confirmation with checkboxes


Delete confirmation with checkboxes

Reply
  #1 (permalink)  
Old 10-30-06, 11:24 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Delete confirmation with checkboxes

I have more checkbox on page.
When user check a checkbox and click on submit button, a row deleted from database.

Before PHP delete this row from database I want to show a confirmation window : "Are you sure you want to delete the selected items?"

If no checkbox selected on page, I don't want to see the confirmation window after submit.

Code:
<tr>
<td><input type="checkbox" name="delete[]" value="1">Apple</td>
</tr>
<tr>
<td><input type="checkbox" name="delete[]" value="2">Pear</td>
</tr>
<tr>
<td><input type="checkbox" name="delete[]" value="3">Orange</td>
</tr>
I think the code is simple but I don't know much JavaScript. I need to implement this in "Trash" folder (private messaging).

What exactly I need: I need to see if checkbox checked, if yes show the confirmation window. If no checkbox selected don't show the confirmation window.

I appreciate any help !
Reply With Quote
  #2 (permalink)  
Old 10-30-06, 11:31 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Something like that?
Code:
<script type="text/javascript">

function confirm_delete()
{
	var boxes = document.getElementsByTagName('input');
	
	for (var i in boxes)
	{
		if (boxes[i].type == 'checkbox' && boxes[i].checked)
		{
			return confirm("Do you really want to delete these items?");
		}
	}
	
	alert("Please select an item.");
	return false;
}

</script>

<input type="submit" onclick="return confirm_delete();" />
Reply With Quote
  #3 (permalink)  
Old 10-31-06, 12:24 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much, your example work for me
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help using checkboxes to delete multiple rows from database. Cheney PHP 5 02-16-06 12:56 AM
Delete confirmation box Programme JavaScript 1 08-08-05 03:56 AM
Delete confirmation box Programme PHP 3 08-07-05 11:27 AM
i know how to delete a file! but how to delete a directory? forcer JavaScript 3 01-28-04 07:00 AM
asp: validating checkboxes in groups by groupid seala ASP 0 09-08-03 01:36 PM


All times are GMT -5. The time now is 11:20 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.