CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 CCS: Javascript Confirmation of Delete?

Print topic Send  topic

Author Message
george l.
Posted: 09/16/2002, 10:18 AM

Does anyone have some WORKING example of a Javascript confirm when clicking on a delete button of a record?

I don't seem to be having much success with what I've found on this forum.

Here is what I've tried so far:
IN THE DELETE BUTTON "ON CLICK" EVENT:
Assuming formname is edit_usr and pagename is usermodify.php

if (document.forms["edit_usr"])
document.edit_usr.onsubmit=delconf;
function delconf() {
if (document.usermodify.FormAction.value == 'delete')
return confirm('Are you sure you want to delete this user?');
}

This does not seem to work. Any ideas where to place this confirm code or if my code would even work? This used to work in CC v2!!!
EMG
Posted: 09/16/2002, 11:10 AM

in the button's client onclick event put the following

return confirm("Delete record?");
george l.
Posted: 09/17/2002, 6:53 AM

This does not seem to work. C.C.S keeps generating this bind_events() function and it's failing in the Javascript Console!

Keep getting:
Error: document.forms.edit_usr.all has no properties
Source File: http://webdev.dal.dset.com:3000/admin/edituser.php?uid=929183352
Line: 40


Don't know why.
EMG
Posted: 09/17/2002, 7:06 AM

the script is good, I think your problem lies elsewhere. Try creating a whole new test page with script. Something is squirrely somewhere...
george l.
Posted: 09/17/2002, 7:30 AM

I agree. This shouldn't be that hard.
teufel
Posted: 09/26/2002, 5:27 AM

I have entered the following custom code associated with the DELETE button of a record in order to popup a JavaScript message before actually deleting the record (CCS automatically creates a JS variable named 'result', so all I did was to attribute my return value to this variable which is then returned):

result = confirm('Do you really want to delete this record?');

The generated code looks like below:

<script language="JavaScript">
//Begin CCS script
//Include JSFunctions @1-DA3E7A20
</script>
<script language="JavaScript" src="functions.js">
</script>
<script language="JavaScript">

//End Include JSFunctions

//page_alunos_Delete_OnClick @49-880B4AD9
function page_alunos_Delete_OnClick()
{
var result;
//End page_alunos_Delete_OnClick

//Custom Code @97-2A29BDB7
// -------------------------
result = confirm('Do you really want to delete this record?');
// -------------------------
//End Custom Code

//Close page_alunos_Delete_OnClick @49-BC33A33A
return result;
}
//End Close page_alunos_Delete_OnClick

//bind_events @1-0BF9872C
function bind_events() {
document.forms["alunos"].all["Delete"].onclick = page_alunos_Delete_OnClick;
}
//End bind_events

window.onload = bind_events; //Assign bind_events @1-19F7B649

//End CCS script
</script>

--------

1) When I get to the record page coming from a link in a grid (that is, I enter in the page to EDIT the record), the page loads fine and the JavaScript works beautifully when I click over the DELETE button.

2) On the other hand, when I get to the page to INSERT a new record, the following JS error message is popped-up by my browser (I am translating it from Portuguese):

Error in execution time. Do you want to debug it?

Line: 33
Error: 'document.forms.alunos.all.Delete' is null or is not an object


-----

Line 33 is function bind_events(). So it is not working because I enter in *insert mode* and the code CCS generates automatically always 'binds' the delete event, although I have no delete button.

Which is then the correct way to implement this simple delete confirmation JavaScript??? I used to do it with CC really easily. The code I found in this forum was a suggesttion to put the code at the form footer, but I don't see why I should not do it the 'right way', i.e., trigger the warning message after the button's 'onclick' event....

Any ideas?

TIA,
Paulo

teufel
Posted: 09/26/2002, 5:27 AM

I have entered the following custom code associated with the DELETE button of a record in order to popup a JavaScript message before actually deleting the record (CCS automatically creates a JS variable named 'result', so all I did was to attribute my return value to this variable which is then returned):

result = confirm('Do you really want to delete this record?');

The generated code looks like below:

<script language="JavaScript">
//Begin CCS script
//Include JSFunctions @1-DA3E7A20
</script>
<script language="JavaScript" src="functions.js">
</script>
<script language="JavaScript">

//End Include JSFunctions

//page_alunos_Delete_OnClick @49-880B4AD9
function page_alunos_Delete_OnClick()
{
var result;
//End page_alunos_Delete_OnClick

//Custom Code @97-2A29BDB7
// -------------------------
result = confirm('Do you really want to delete this record?');
// -------------------------
//End Custom Code

//Close page_alunos_Delete_OnClick @49-BC33A33A
return result;
}
//End Close page_alunos_Delete_OnClick

//bind_events @1-0BF9872C
function bind_events() {
document.forms["alunos"].all["Delete"].onclick = page_alunos_Delete_OnClick;
}
//End bind_events

window.onload = bind_events; //Assign bind_events @1-19F7B649

//End CCS script
</script>

--------

1) When I get to the record page coming from a link in a grid (that is, I enter in the page to EDIT the record), the page loads fine and the JavaScript works beautifully when I click over the DELETE button.

2) On the other hand, when I get to the page to INSERT a new record, the following JS error message is popped-up by my browser (I am translating it from Portuguese):

Error in execution time. Do you want to debug it?

Line: 33
Error: 'document.forms.alunos.all.Delete' is null or is not an object


-----

Line 33 is function bind_events(). So it is not working because I enter in *insert mode* and the code CCS generates automatically always 'binds' the delete event, although I have no delete button.

Which is then the correct way to implement this simple delete confirmation JavaScript??? I used to do it with CC really easily. The code I found in this forum was a suggesttion to put the code at the form footer, but I don't see why I should not do it the 'right way', i.e., trigger the warning message after the button's 'onclick' event....

Any ideas?

TIA,
teufel

EMG
Posted: 09/26/2002, 6:39 AM

when the form loads for an insert, the delete button is removed but the javascript to it remains, therefore throwing an error.

Solution:
put an if statement to confirm the presence of the delete button:

function bind_events() {

if (document.alunos.Delete)
document.forms["alunos"].all["Delete"].onclick = page_alunos_Delete_OnClick;



teufel
Posted: 09/30/2002, 6:54 PM

Here is the suggestion of Support (by far the best and simplest, since you do not generate useless code - I don't need this stupid 'if' condition on the first place...):

"Add the Javacript event code directly to the HTML tag for the delete button so that it is only executed when the delete button appears. If you use a client side event, the code will always fail when the record form is in insert mode."

So for example:

<!-- BEGIN Button Delete --><input class="CapuccinoButton" type="submit" value="Remove" name="Delete" onClick="return confirm('Do you really want to delete this record?');"><!-- END Button Delete -->

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.