Solved

Dynamically generated Javascript Comfirm/Redirect links

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

827 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