Alert Box

 

The JavaScript alert is a dialogue box that pops up and takes the focus away from the current window and forces the web browser to read the message. You must have JavaScript enabled on your web browser (but most people do these days). Alerts should be very, very rarely used and only when really needed. So this is definitely a case of "Just because you can, doesn't mean you should."

Click Here

Simple onClick Alert

html
  1. <p class="center">
  2. <a class="button" "HREF="#" ONCLICK="alert('Hello There! This is a sample of an easy alert');">Click Here</a>
  3. </p>

Possible Uses:

For Fun:

Just for fun, let's suppose that we are making an alert for your site that asks people to hand over $100 every month. We need to add an alert to be sure these people are in agreement. The following code will add an alert by using an HTML button and the onClick event.

form stuff here


Form onClick Alert

html
  1. <form> <!-- Is not active, so it doesn't go anywhere! -->
  2. <input type="button" onclick=
  3. "alert('Are you sure you want to give me $100 each month?')"
  4. value="Confirmation Alert">
  5. </form>

Note: The samples above are simple ones. If you need something a bit more complex, you can do a search for "Javascript Alert Boxes" and can find a lot of examples along with instructions on how to implement them. Also note that an alert box is a function of the operating system, so it cannot be styled with CSS (although there are some jQuery scripts that can make the alert a bit fancier.)