Michael
Michael

Reputation: 2187

embed javascript function in html

I want to use a confirm box for user to check before submitting the form. I use the following form tag in my script:

<form action="delete.php" method="POST" target="_blank" onsubmit="return confirm(\"Are you sure you want to delete it from the database?\");">

But it is not working, after I click "submit" button, the "delete.php" will be executed. Can anyone help me figure out where I went wrong? I wonder is it because this "confirm" function is some sort of inline style that I need to do some reference in the <head> tag? Thanks!

Upvotes: 0

Views: 358

Answers (1)

Austin Brunkhorst
Austin Brunkhorst

Reputation: 21130

onsubmit="return confirm('Are you sure you want to delete it from the database?');"

Tested, and works. I don't think you can escape characters like that in tags.

Upvotes: 1

Related Questions