• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using a java script comfirmation in delete record function?

Contributor ,
Jan 21, 2008 Jan 21, 2008

Copy link to clipboard

Copied

Hello;
I am trying to write a confirmation script in Java to delete a record. I don't want it to delete the whole table of information, just the record teh delete button is attached to using the ID. Here is my script, and then the code on the page:

<script language="JavaScript">
function confirmDelete(id) {
if (confirm ("Are you sure you want to delete this record?"))
{
document.HREF.action="ProjectCat-Action.cfm?id="+id;
document.HREF.submit();
}
return false;
}

</script>

Here is the query I am trying to use it with:
<cfquery name="catMan" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
SELECT Categories.Name AS ViewField1, Categories.CategoryID AS ID
FROM Categories
</cfquery>
<head>
</head>
<body>
<cfloop query="catMan" startRow="#URL.startRow#" endrow="#endRow#">
<cfoutput>
#ViewField1#
<form action="ProjectCat-Action.cfm" method="post">
<input type="hidden" name="ID" value="#ID#">
<input type="submit" name="proj_Delete" onClick="return confirmDelete('#ViewField1#')" value="Delete"></form>
</cfoutput>
</cfloop>
</body>

#Note: there is code here in my loop query for next and previous buttons, I just didn't post that code because it doesn't pertain to this question.

Is there also a way to make the Java Script state in the spot where it says, "Are you sure you want to delete this record" to make it say "Are you sure you want to delete #ViewField1#?" (the name of the record being deleted) ?

Thank you!

Phoenix
TOPICS
Advanced techniques

Views

451

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 21, 2008 Jan 21, 2008
just pass 2 arguments to your js function - id AND name of category:

<input type="submit" name="proj_Delete" onClick="return
confirmDelete(#ID#,'#ViewField1#')" value="Delete">
and the function:
function confirmDelete(id,name) {
if (confirm ("Are you sure you want to delete " + name + " category?"))
{
document.HREF.action="ProjectCat-Action.cfm?id="+id;
document.HREF.submit();
}
return false;
}


but creating a separate form for each category displayed on the page is
very inefficient -...

Votes

Translate

Translate
LEGEND ,
Jan 21, 2008 Jan 21, 2008

Copy link to clipboard

Copied

Since you can only submit one form at a time, it's probably simpler to put your js code right into the input tag. Here is one that I once wrote

<input
type="button"
value="Delete"
name="DeleteOneRecord" onclick="if(confirm('Delete this record?')){this.form.WhatToDo.value='DeleteOneRecord';this.form.submit()}">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 21, 2008 Jan 21, 2008

Copy link to clipboard

Copied

when you hit the cancle button on your code, it still sends you off to the action page. Is there a way to fix that? Or make mine just say do you want to delete ViewField1? (ViewField1 should state the name of the record being deleted.

Right now, mine does delete the one record I am trying to delete and when you hit cancle, it doesn't do anything but close the script box, now i just want it to say the name of the record.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2008 Jan 21, 2008

Copy link to clipboard

Copied

LATEST
just pass 2 arguments to your js function - id AND name of category:

<input type="submit" name="proj_Delete" onClick="return
confirmDelete(#ID#,'#ViewField1#')" value="Delete">
and the function:
function confirmDelete(id,name) {
if (confirm ("Are you sure you want to delete " + name + " category?"))
{
document.HREF.action="ProjectCat-Action.cfm?id="+id;
document.HREF.submit();
}
return false;
}


but creating a separate form for each category displayed on the page is
very inefficient - you should revise your code... you do not even need a
form, really... just use <a href=...> to call your js function, or an
<input type=button ...> (without any <form ..> tags) if you absolutely
must have a button to click...

---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation