-3

Hey i'm trying to make use of onclick =return confirm but whenever I click on the button, no prompt appears and it just heads to the redirect. My front end development isn't really the best. Any help is appreciated. Thanks

<td><a href="delete.php?id='.$row["userID"].'" onclick="return confirm("Are you sure you want to delete ?")" class="waves-effect waves-light btn-small red lighten-1"><i class="material-icons">delete</i></a></td>
  • ahh ok gotcha...But i fixed all of those problems, but the problem isnt fixed...hmmm – OzosStackOverflow Nov 21 '21 at 10:50
  • 1
    Inline event handlers like `onclick` are [not recommended](/q/11737873/4642212). They are an [obsolete, hard-to-maintain and unintuitive](/a/43459991/4642212) way of registering events. Always [use `addEventListener`](//developer.mozilla.org/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. – Sebastian Simon Nov 21 '21 at 10:54

2 Answers2

0

If you don't surround an attribute value with quotes, then the value ends at the first space.

You have:

onlick=return

Your second problem is that you forgot the c


Using the Inspector feature in your browser to see what attribute is actually generated is a useful debugging technique that would have helped you narrow down the problem here.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You can try this which works for me :

echo "<td><a onClick=\"javascript: return confirm('Are You sure to delete this');\" href='delete.php?id=".$res['id']."'>Delete</a></td>";
Elikill58
  • 4,050
  • 24
  • 23
  • 45