August 17, 2024
JavaScript Alert
Alert boxes are usually use to display some information on user's screen for example suppose you want to show a warning when user clicks on a button or user try to access some restricted contents of your website. You can show welcome message on the screen when user open your website. You can also show an error message when some content or some part of your website does not working. You can show some informational messages for example suppose a user is filling personal information form and he/she left some important field blank of personal information form so you can show informational messages that which kind of data required for particular field. Example of alert box is mentioned below:
Code
<html>
<head>
<title>Alert Example</title>
</head>
<body onload='alert("Welcome to my first webpage.")'>
<form name='myForm' method='post'>
<input type='button' name='btn1' value='Click Me'
onclick='alert("You just clicked the Button")' />
</form>
</body>
</html>
In the above mentioned example whenever you will open this file on your browser. Then a welcome message will appear on the screen which we have included in body tag's onLoad event. And in above mentioned example a button also present and we have included an alert on it's onClick event, when user will click on this button then you will get an another alert. So like this you can add alerts on different JavaScript events.