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

JavaScript Prompts for ColdFusion File Delete 5

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
I have a listing of different files. Users are able to delete files via a ColdFusion template, but I want to build a customized JavaScript PROMPT (I believe that is what it is called) that will say do you want to delete (and then the title that the user entered in when the uploaded the file). There may be multiple files on one page, so how do I build a customized prompt for each one? I want to make it so that if the user click cancel, the user stays on the page, but if they click OK, they are taken to the delete page (the primary key must be passed).

Ryan ;-]
 
I put this one together a long time ago and use it to this day:

function confirmDelete()
{
var delConfirm=confirm('Are you sure you want to permanently delete this record?');
if (delConfirm==true)
{
return true;
} else {
return false;
}
}

Then in the HTML:

<a href=&quot;Delete.cfm?ID=#ID#&quot; onClick=&quot;return confirmDelete()&quot;>[Delete]</a>

You could easily pass the name in when you call confirmDelete and add it into the dialog, for example:

function confirmDelete(delText)
{
var delConfirm=confirm('Are you sure you want to permanently delete record: ' + delText);
if (delConfirm==true)
{
return true;
} else {
return false;
}
}

Then HTML:

onClick=&quot;return confirmDelete('#Trim(Name)#')&quot; Andrew
 
Thanks a lot. It works great!

Ryan ;-]
 
AMayer...

just thought you might like to 'one line' it...

function confirmDelete()
{
return confirm('Are you sure you want to permanently delete this record?')
}

cheers!
 
<a href=&quot;Delete.cfm?ID=#ID#&quot; onClick=&quot;return confirm('Are you sure you want to permanently delete this record?')&quot;>[Delete]</a>
 
Thanks, but I had to pass a ColdFusion variable with the JavaScript, and AMayer's code works very well. Your's does not accommodate this.

Ryan ;-]
 
what I asking is ... you can't do this?

<a href=&quot;Delete.cfm?ID=#ID#&quot; onClick=&quot;return confirm('Are you sure you want to permanently delete #variable#')&quot;>[Delete]</a>

curiously,

Marc
 
Oh, sorry, I was wrong. I thought you didn't put &quot;return&quot; in front of the confirmation, so it would process the delete anyway. Thanks a lot. This method works well and I have implemented it instead.

Ryan ;-]
 
Changing the return to be on the same line is a good move. My JavaScript is a little weak so I learn as I go along. I still prefer to detach the function from the HTML because I usually put my JavaScript in an include so if one day I want to change my delete prompt I don't have to do it in a hundred places. It's already happened a couple times over the last year.

Thanks Marc! Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top