button tag inline onclick confirm ask to delete
- User
button tag inline onclick confirm ask to delete
Assistant
Here's how you can create a button with an inline onclick event that shows a confirmation dialog for deletion:
<button onclick="if(confirm('Are you sure you want to delete this item?')) { deleteItem(); }"> Delete </button>Or a more readable version:
<button onclick="confirmDelete()">Delete</button> <script> function confirmDelete() { if (confirm('Are you sure you want to delete this item?')) { // Add your delete logic here console.log('Item deleted'); // Or call your delete function // deleteItem(); } } </script>You can also make it more specific:
<button onclick="if(confirm('Are you sure you want to permanently delete this record? This action cannot be undone.')) { window.location.href='/delete/123'; }"> Delete Record </button>The
confirm()function returns if the user clicks "OK" and if they click "Cancel", so you can use it in an if statement to conditionally execute the delete action.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.