I'll make this as clear as I can.
Basically, my form allows you to delete players from a selection box.
When the user presses 'Delete', a confirmation box appears, telling the user that if they proceed, they can't get that data back. The intended behaviour is that when the user presses "OK", the deletion script will run and delete the player. If you remove the confirmation box and allow the default behaviour of the submit button, it works like I want it to. I would just be more professional if I could add that intermediate step.
Here is my relevant HTML Code:
<form id="player-list" action="edit-player.php?playerid=22" method="post">
<div id="player-box" class="row">
<div class="small-12 medium-offset-4 medium-4 columns">
<label>Team
<select id="all-players" name="team-division">
<?php
$SQL = "SELECT
ID,
firstName,
lastName
FROM
players";
$playerResult = mysqli_query($link, $SQL);
$counter = 1;
while($row = mysqli_fetch_array($playerResult)) {
echo '<option value="player-' . $row['ID'] . '">' . substr($row['firstName'], 0, 1) . " " . $row['lastName'] . '</option>';
}
?>
</select>
<br />
</label>
</div>
</div>
<div class="row">
<div class="small-12 medium-2 medium-offset-4 columns ">
<a id="player-selection" class="button expanded radius success">Submit</a>
</div>
<div class="small-12 medium-2 columns end">
<input type="submit" id="player-deletion" class="button expanded radius alert" name="delete-player" value="Delete" />
</div>
</div>
</form>
The input #player-deletion tag is what is important here.
Relevant jQuery code:
$("#player-deletion").on('click', function(e) {
e.preventDefault();
var x;
if (confirm("This record will be permanentely deleted. Is that OK?") == true) {
$(e).trigger('submit');
}
});
This code doesn't work. I know I have to prevent the default action happening, but after the user has clicked 'OK', I would like to refire the submit function from the confirmation button.
Is this possible?
Any help would be appreciated.
Thanks.
You can just return whatever the confirm
returns. return false
would be the same as calling e.preventDefault()
and e.stopPropagation()
. Stopping the event propagation is what will cancel the submit.
$("#player-deletion").click(function(e) {
return confirm("This record will be permanentely deleted. Is that OK?");
});