[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Dynamically generated Javascript Comfirm/Redirect links

Posted on 2004-08-12
3
Medium Priority
?
409 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 800 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

590 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