arunpatal Posted January 3, 2013 Share Posted January 3, 2013 Hi, i am trying this java script to confirm before action can take place the message come that if i want to delete this topic but when i click yes..... it doesn't delete the topic..... Here is java code <script type="text/javascript"> function runCheck() { var c = confirm("Are you sure you want to delete this topic?"); var status = document.getElementById("status"); if (c == true){ status.innerHTML = "You confirmed, thanks"; } else { status.innerHTML = "You cancelled the action"; } } </script> Here is form code.... <?php do { ?> <?php if (isset($row_category_list['cat_descrip'])) { echo '<div id="right_td_content_for_list"> <table><tr><td width="650px">'.$row_category_list['cat_descrip'].' </td><td width="150px">'; ?> <a href="edit_cat.php?id='.$row_category_list['cat_id'].'">EDIT</a> - <input name="" type="button" onclick="runCheck()" value="Delete" onclick="parent.location='del_cat.php?id=<?php echo $row_category_list['cat_id']; ?>'"/> I just need that before i can delete any topic.... it shows msg like if i am sure.... Please help me with this Quote Link to comment https://forums.phpfreaks.com/topic/272656-delete-confirm-button/ Share on other sites More sharing options...
codefossa Posted January 3, 2013 Share Posted January 3, 2013 Something like this would probably work out better. Inside the if (del) you could do whatever you want it to do when you delete. I just let the form continue submitting, but in your case it may be different. You could use Ajax or whatever you want in there. On a side note, you shouldn't use $_GET parameters to delete anything. What if a spider comes and scans them links, wherever they're posted, or people trick each other into going to them. You should use $_POST. Demo: http://xaotique.no-ip.org/tmp/38/ window.addEventListener('load', function() { window.document.querySelector("#myForm").addEventListener('submit', function(event) { event.preventDefault(); var del = confirm("Are you sure you want to delete this topic?") ? true : false; var status = del ? "You confirmed, thanks!" : "You cancelled the action."; window.document.querySelector("#status").innerHTML = status; if (del) window.document.querySelector("#myForm").submit(); }, false); }, false); Quote Link to comment https://forums.phpfreaks.com/topic/272656-delete-confirm-button/#findComment-1403044 Share on other sites More sharing options...
arunpatal Posted January 3, 2013 Author Share Posted January 3, 2013 Something like this would probably work out better. Inside the if (del) you could do whatever you want it to do when you delete. I just let the form continue submitting, but in your case it may be different. You could use Ajax or whatever you want in there. On a side note, you shouldn't use $_GET parameters to delete anything. What if a spider comes and scans them links, wherever they're posted, or people trick each other into going to them. You should use $_POST. Demo: http://xaotique.no-ip.org/tmp/38/ window.addEventListener('load', function() { window.document.querySelector("#myForm").addEventListener('submit', function(event) { event.preventDefault(); var del = confirm("Are you sure you want to delete this topic?") ? true : false; var status = del ? "You confirmed, thanks!" : "You cancelled the action."; window.document.querySelector("#status").innerHTML = status; if (del) window.document.querySelector("#myForm").submit(); }, false); }, false); Thanks i will try this code and get back to you Quote Link to comment https://forums.phpfreaks.com/topic/272656-delete-confirm-button/#findComment-1403048 Share on other sites More sharing options...
arunpatal Posted January 3, 2013 Author Share Posted January 3, 2013 Thanks.... Its working nice Quote Link to comment https://forums.phpfreaks.com/topic/272656-delete-confirm-button/#findComment-1403060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.