Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP/JavaScript Question.

PHP/JavaScript Question.
Thread Tools
Grizzled Veteran
Join Date: Aug 2002
Status: Offline
Reply With Quote
Apr 12, 2005, 05:00 AM
 
Hello, I have the following line of code...

<td><? echo '<a href=delete.php?id='. $id .'>' . Delete . '</a>'; ?></td>

How can I add a JavaScript confirmation box to this line of code?

Thank!
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Apr 12, 2005, 05:58 AM
 
Well, since you are using a confirm dialogue, you'll want to actually use the users choice.
Here's a small page showing the basics, and degrades for those without javascript enabled/capable browsers.

Code:
<html> <head> <title>Confirm</title> <script> function goTo(url) { if (confirm("Do you want to go to " + url + "?")) document.location.href = url; } </script> </head> <body> <a href="http://www.apple.com" onclick="goTo(this.href); return false">Go to Apple</a> </body> </html>
Hope that helps.
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Grizzled Veteran
Join Date: Aug 2002
Status: Offline
Reply With Quote
Apr 12, 2005, 06:35 AM
 
Originally posted by Black Book:
Well, since you are using a confirm dialogue, you'll want to actually use the users choice.
Here's a small page showing the basics, and degrades for those without javascript enabled/capable browsers.

Hope that helps.

Yeah, I tried some other code similar to what you have above but I can't get it to work with the PHP code that I posted.
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Apr 12, 2005, 06:52 AM
 
something.php:

[php]
<html>
<head>
<title>Confirm</title>
<script>
function goTo(url) {
if (confirm("Do you want to go to " + url + "?"))
document.location.href = url;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<a href="delete.php?id='<?php echo $id ?>'" onclick="goTo(this.href); return false">Go to Apple</a>
</td>
<td> Something else</td>
</tr>
</table>
</body>
</html>
[/php]

What is actually happening at your end for it not to be working? What errors is it throwing?
(Last edited by Black Book; Apr 12, 2005 at 06:58 AM. )
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Grizzled Veteran
Join Date: Aug 2002
Status: Offline
Reply With Quote
Apr 12, 2005, 07:04 AM
 
That got it! Thanks!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2