Let’s talk about alerts for a second. You already had a small introduction in my previous post.
Alerts are basically just pop-up boxes with an OK and or Cancel button. And yes.. Yes indeed, you can create some very irritating webpages by using these alerts.
However they could come in handy as well.
Let’s say you want to create a check on a field in a form. It should not be empty and you need to make sure the website visitor knows this… In an irritating way.
We’ll start off with our basic HTML script again:
Good now… Let’s create a small form:
The result looks like this:
The code for this function looks as followed:
It’s not so hard. First 2 variables are initialized which contain the values of the textfields in the form. Next there is and if else check to see if these fields are empty. Once everything is filled in (you’ll get to the else section of the function) an alert is shown with the message “Hello Firstname Lastname”.
The complete script looks like this:
The result of this script:
Tadaa! You can amaze everyone again with your newly learned skill.
Oh by the way, this is one way to write this script. There are dozens of other ways to write this script.. I just picked one…
Let me know if you have questions…