Solved

Dynamically generated Javascript Comfirm/Redirect links

Posted on 2004-08-12
3
383 Views
Last Modified: 2012-06-21
I know a lot about ASP and databases, but javascript just boggles me. =]

I have a bunch of 'delete' links on a page that have a lot of power behind them. I want to add a confirmation window to confirm the delete before it happens.

I found this code that seems to provide the functionality i want:
<a href="#" onclick="Javascript:if (confirm('Confirm delete?')) {window.location.href = 'b.html logmeout=true'; return false}">Delete</a>

But what i need to do is write the code into a function and be able to write out onclicks for each item in the recordset that will send their unique IDs to the function so it redirects to the correct URL that executes the delete.

Here's the ASP line inside a WHILE loop, reading from a SQL Recordset:
Response.write "<a href='sites.asp?co=" & intCompanyID & "&dv=" & intDivisionID & "&deleteSite=" & rsSite("S_ID").Value & "'>Delete</a>"

It's always going to go to sites.asp.
intCompanyID and intDivisionID are defined at the beginning of the page.
rsSite("S_ID") is the site ID being looped from the recordset.

What would be awesome is a javascript function to put in the script tags at the top of the page, and a small tag i can add to my links like

<a href="#" onclick="Javascript:deleteConfirm(1,3,123)">Delete</a>
or in the ASP loop it would look like:
response.write "<a href='#' onclick='Javascript:deleteConfirm(=" & intCompanyID & "," & intDivisionID & "," & rsSite("S_ID").Value" & "')">Delete</a>

Thanks
Mike Miller
0
Comment
Question by:MikeMiller
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 200 total points
ID: 11786612
Hi

Er... you mean like this?

<script language="javascript">
<!--

function deleteConfirm(compId,intDivId,sid) {
   if (confirm("Confirm delete?")) {
      window.location.href = "sites.asp?co=" + compId.toString() + "&dv=" + intDivId.toString() + "&deleteSite=" + sid.toString();
   }
}

// -->
</script>

Regards,
Zyloch
0
 
LVL 3

Author Comment

by:MikeMiller
ID: 11787176
Yes. Thats great!

Can you confirm the proper syntax for the href?:

<a href="#" onclick="Javascript:deleteConfirm(1,3,123)">Delete</a>

Does that look ok?

Thanks
Mike
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11787551
If you have deleteConfirm(1,3,123), the resulting href should be

sites.asp?co=1&dv=3&deleteSite=123

Yep, looks fine. You might want to take out the javascript: prefix though. that's mainly for the href even though you can use it here.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now