Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/272656-delete-confirm-button/
Share on other sites

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);

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.