0

I have created a checkDelete function to ask the user if he wants to delete the selected entries from a database. The problem is that choosing cancel still deletes those entries.
This is the function:

function checkDelete (){
    var answer = confirm("Are you sure you want to delete the selected entries?");
    if (answer == true) {
        document.forms[0].submit()
    }
    else 
    }
    </script>

thank you.

Edited by mike_2000_17: Fixed formatting

5
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by almostbob
-1

It seems that the entries are deleted because the form is submitted to the server even after you click cancel on the confirm box. One of the reason for this could be that the delete button could be of the type submit
e.g.
<input type="submit" name="Delete">
make the type of normal button.
i.e
<input type="button" name="Delete">

It would help if you could post your complete code of the web page related to this functionality

0

This is the code:

echo "<form action='change.php?modify_type=2' onsubmit='checkDelete()' method='post'>";

foreach($rows as $row){
echo "<input type='checkbox' name='delete_id[]' value='".$row[0]."'>";
}

echo "<input type='Submit' value='Delete'>";
0

I have returned false on the else branch but it is still deleting

1

Yup as pritaeas suggested, do

echo "<form action='change.php?modify_type=2' onsubmit='return checkDelete()' method='post'>";

And return false from the javascript function when cancel is clicked,

function checkDelete (){
var answer = confirm("Are you sure you want to delete the selected entries?");
if (answer == true) {
   document.forms[0].submit()
}
else {
   return false;
}
}
</script>
0

I have created a checkDelete function to ask the user if he wants to delete the selected entries from a database. The problem is that choosing cancel still deletes those entries.
This is the function:

function checkDelete (){
    var answer = confirm("Are you sure you want to delete the selected entries?");
    if (answer == true) {
        document.forms[0].submit()
    }
    else 
    }
    </script>

thank you.

just add return from where u r calling this checkDelete() function like parry_kulk as said
something like

function submit()
{
 return checkDelete()
}

function checkDelet()
{


}

Edited by mike_2000_17: Fixed formatting

0

everybody always wants to do it the hard way echo "<form action='change.php?modify_type=2' onsubmit='return confirm(\"Are you sure you want to delete the selected entries?\");' method='post'>"; keep it small

Edited by almostbob: I wish I could SPELL

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.