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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirming Delete when Delete is not the only submit button

Status
Not open for further replies.

kathryn

Programmer
Apr 13, 2000
776
0
0
US
Good afternoon.

I have a form which is used to maintain employee information. When editing an existing employee, the form has both an delete and update button.

This is the code for the buttons:

<input type=&quot;submit&quot; value=&quot; #formAction# &quot; name=&quot;#formAction#&quot;>
<cfif NOT compareNoCase(formAction,&quot;Update&quot;)>
<input type=&quot;submit&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; >
<input type=&quot;reset&quot; value=&quot; Reset &quot;>
<input type=&quot;button&quot; value=&quot; Cancel &quot; onClick=&quot;document.location.href='javascript:history.back();'&quot;>

The formaction variable can be Insert or Update. I am concerned with the case where it is Update, because that is when I get both an Update and Delete button.

I want to show a confirm box to confirm any deletions.

I found this Javascript:

<!--- this script confirms deletes, I hope --->
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function confirmDelete() {
if (confirm(&quot;Are you sure you want to delete this employee?&quot;)) {
return true;
}
else {
return false;
}
}
</script>

and I added it to the page and edited the buttons so that the Delete button read:

<input type=&quot;submit&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; onClick =&quot;return confirmDelete();&quot; >

When I ran the page, the Javascript didn't run, apparently. The form posted to the post page and the data was deleted with no confirmation.

The post page differentiates between the actions and runs the apppropriate query as follows:

<cfif isDefined(&quot;form.insert&quot;)>
<cfmodule
template=&quot;qryInsertRecord.cfm&quot;
table=&quot;#table#&quot;>
<cfset verb=&quot;inserted&quot;>
<cfelseif isDefined(&quot;form.update&quot;)>
<cfmodule
template=&quot;qryUpdateRecord.cfm&quot;
table=&quot;#table#&quot;
ID=&quot;#ID#&quot;>
<cfset verb=&quot;updated&quot;>
<Cfelseif isDefined(&quot;form.Delete&quot;)>
<cfmodule
template=&quot;qryDeleteRecord.cfm&quot;
table=&quot;#table#&quot;
ID=&quot;#ID#&quot;>
<cfset verb=&quot;deleted&quot;>
</cfif>

Can anyone shed some light on how to do what I want?

Kathryn


 
I copied and pasted your code into a test file and it did the same thing that you described. The page submitted without showing a confirmation box. I removed the line break in your delete button &quot;<input type=&quot;submit&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; onClick =&quot;return
confirmDelete();&quot; >&quot; so that it became one line &quot;<input type=&quot;submit&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; onClick =&quot;return confirmDelete();&quot; >&quot; and it started working. I just assumed the line break got added when you posted the code but I'm wondering if this is really in your code. If so, this might be your problem as the code works for me.

GJ
 
If the problem has nothing to do with the posting of your message, try the following:

<input type=&quot;button&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; onClick=&quot;confirmDelete(this.form);&quot;>

<!--- this script confirms deletes, I hope --->
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function confirmDelete(MyForm) {
if (confirm(&quot;Are you sure you want to delete this employee?&quot;)) { document.MyForm.submit() }
}
</script>






<webguru>iqof188</webguru>
 
Thanks for the replies.

I finally got it working by putting the delete button into a second form on the page and calling the Javascript from the onSubmit of that second form.

I'm posting the archival purposes:

<td colspan=2>
<br>
<input type=&quot;submit&quot; value=&quot; #formAction# &quot; name=&quot;#formAction#&quot;>
<cfif NOT compareNoCase(formAction,&quot;Update&quot;)>
<input type=&quot;reset&quot; value=&quot; Reset &quot;>
<input type=&quot;button&quot; value=&quot; Cancel &quot; onClick=&quot;document.location.href='javascript:history.back();'&quot;>
</cfif>
</td>
</tr>
</CFFORM> <!--- END OF FIRST FORM --->

<!--- this form is necessary because of the multiple sumit buttons --->
<cfif NOT compareNoCase(formAction,&quot;Update&quot;)>
<tr>
<td> </td>
<td align=&quot;center&quot;>
<CFFORM
name=&quot;EmployeeMaintenanceDelete&quot;
action=&quot;addUpdateFormPost.cfm?table=#table#&amp;ID=#qryEmployeeData.EmployeeID#&quot;
method=&quot;post&quot;
onSubmit=&quot;return confirmDelete();&quot;>
<input type=&quot;submit&quot; value=&quot; Delete &quot; name=&quot;Delete&quot; >
</cfform>
</td>
</tr>
</cfif>
</TABLE>



Kathryn


 
<form action=&quot;somepage.xxx&quot; method=&quot;post&quot;>

// your code

<input type=&quot;submit&quot; value=&quot;update&quot;>

....

<input type=&quot;submit&quot; value=&quot;delete&quot; onClick=&quot;return confirm('Are you sure?')&quot;>

</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top