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?
maccaj51Asked:
Who is Participating?
 
haloexpertsexchangeConnect With a Mentor Commented:
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.