Solved

Dynamically generated Javascript Comfirm/Redirect links

Posted on 2004-08-12
3
388 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

749 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