Quantcast
Channel: Swedish fika » Javascript
Viewing all articles
Browse latest Browse all 2

Display confirm box when clicking a link

$
0
0

There are many times when you want the user to confirm an option he/she tries to perform and in this example I will show how you can use a simple Javascript to display a confirm box when a user clicks on a link.

The XHTML

<a href="test.html">Delete user</a>

Now add the onclick attribute and write the Javascript

<a href="test.html" onclick="return confirm('Are you sure?');">
Delete user
</a>

If the user clicks on the link he/she must confirm the action. If the user clicks on the OK button in the confirm box the link will be followed, if not the link will not be followed.

/Simon Kjellberg


Viewing all articles
Browse latest Browse all 2

Trending Articles