>> SPEAKER: Let's refine that last implementation by leveraging jQuery to
relocate my JavaScript code to the head of my page so that I don't need
to, somewhat arbitrarily, paste it below the form my body.
Notice here that I first included in my page's head a script tag, the
source of which is the URL of jQuery, that popular JavaScript library.
Below that is another script tag inside of which is my own code.
In this first line of code, I specify, using jQuery that I'd like to execute
the following anonymous function when the so-called document is ready.
>> Specifically, I would like to first get the element from the page whose
unique ID is registration, that is my form.
I'd like to register an event handler for the form submission and execute
the following anonymous function whenever that event triggered.
Specifically, I'd like to get using jQuery, the element, whose unique
identifier is registration, but from there grab the child of type input
that happens I have an attribute called name whose value is email.
>> Once done, I'd like to get the value that the user has provided for that
form field and check does it equal quote unquote with nothing in between.
If so, I'd like to yell at the user that he or she must provide their
email address.
>> Meanwhile I'd like to do something similar, checking whether that form,
whose idea is registration, has an input field as a child, that has a
name attribute whose value is password.
And check, too, if the user's value for that is, quote unquote, "nothing."
If so, I'd like to yell at the user, emphasizing that he or she must
provide a password.
>> Meanwhile, I'd also like to check if that form whose ID is registration,
has an input child whose name attribute equals password, has a value
that does not equal the value that the user has typed in for the field that's
that similarly structured, but whose name is confirmation.
If so, I want to yell at the user that his or her passwords do not match.
>> Lastly, let's check if the registration form's input, whose name
is agreement, is checked.
And if so, let's negate that answer with bang and then yell at the user
that he or she must agree to the terms and conditions.
>> In each of these cases when the user has erred, we return false to prevent
the form submission to register.php.
Else, if no mistakes have been made, we instead return true, thereby
indicating that the form should indeed be submitted to register.php.
>> Let's take a look in a browser.
Here then is my form.
Let's try to register with nothing.
But nope, I must provide my email address.
Let's do so.
>> Registering again yields that I must provide a password.
Let's do so, this time providing crimson.
>> Passwords do not match because, indeed, I've not confirmed by typing
crimson again.
And now I must agree to the terms and conditions by checking this box,
followed by one final register.
>> And now I am really, well not really, registered.