Learn how to a build a cloud-first strategyRegister Now

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

Javascript/Jquery

Hi Experts,

I have a link script like this...

<a href="/delete.php?type=blog&id=12" class="delete"><img src="/images/delete.png" /></a>

and I want it to do the following...

1) Trigger a warning box "Are you sure you wish to delete?"
2) When clicked yes follow the link
3) reload the page

Can anybody help please?
0
maccaj51
Asked:
maccaj51
  • 5
  • 4
  • 3
1 Solution
 
HainKurtSr. System AnalystCommented:
try:
<a href="/delete.php?type=blog&id=12" class="delete" onClick="return sure()"><img src="/images/delete.png" /></a>
<script>
function sure(){return confirm("Are you sure you wish to delete?");}
</script>

Open in new window

0
 
haloexpertsexchangeCommented:
using a confirm box you can get either a yes or a no answer.

adding an onclick function

function Deletequestion(link)
 var answer = confirm("Are you sure you wish to delete");
     if(answer)
     {   
   return true;
     }
     else
     {
 //do anything you want with a no answer
        return false;
     }

Open in new window

To reload a page you do window.location.reload.
0
 
HainKurtSr. System AnalystCommented:
how can someone do these two at the same time?

2) When clicked yes follow the link
3) reload the page


???
0
Technology Partners: 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!

 
maccaj51Author Commented:
Thanks guys - but i cant get either to work...

HainKurt: They are meant to be steps... one after another
haloexpertsexchange: my knowledge of jquery is poor... could you explain further

0
 
haloexpertsexchangeCommented:
that is plain old javascript no jquery involved.
what you would do was a onClick return Deletequestion on the link itself. You don't actually need to pass anything in to the function unless you want to do something special if there is a return of false and you need extra information.
The link will take its normal action if it gets a return value of true, if it gets a return value of false it will stop and will not follow the link.

<a href="/delete.php?type=blog&id=12" class="delete" onClick="return Deletequestion()"><img src="/images/delete.png" /></a>

Open in new window

0
 
maccaj51Author Commented:
Could you quickly show me a demo html page... Im sorry halo... Im rubbish at this
0
 
haloexpertsexchangeCommented:
try this
I forgot the {} in the function before so that could have been your problem
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            function Deletequestion(link)
     {    
    var answer = confirm("Are you sure you wish to delete");
     if(answer)
     {   
   return true;
     }
     else
     {
 //do anything you want with a no answer
        return false;
     }
     }      
        </script> 
    </head>
    <body>
        <div>
<a href="/delete.php?type=blog&id=12" class="delete" onClick="return Deletequestion()"><img src="/images/delete.png" /></a></div>
    </body>
</html>

Open in new window

0
 
maccaj51Author Commented:
Many Thanks Mate
0
 
HainKurtSr. System AnalystCommented:
did you try the sample I posted on top? which is same as what haloexpertsexchange posted after me :)
0
 
HainKurtSr. System AnalystCommented:
how come you accepted 36932013? which is same as the one I posted above, 36931769?
They are doing the same thing...
0
 
haloexpertsexchangeCommented:
sorry about that, I was typing mine out while you posted yours and didn't see it.
Didn't mean to have the same thing after you.
0
 
HainKurtSr. System AnalystCommented:
it is ok, it happens all the time... the issue is author ignored my post and accepted yours as if I never posted anything... If you look at the first post (by me) basically it is the same thing which he accepted...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now