Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

Dynamically generated Javascript Comfirm/Redirect links

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
MikeMiller
Asked:
MikeMiller
  • 2
1 Solution
 
ZylochCommented:
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
 
MikeMillerAuthor Commented:
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
 
ZylochCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now