1 00:00:00,000 --> 00:00:00,380 2 00:00:00,380 --> 00:00:03,610 >> SPEAKER: Let's refine that last implementation by leveraging jQuery to 3 00:00:03,610 --> 00:00:07,520 relocate my JavaScript code to the head of my page so that I don't need 4 00:00:07,520 --> 00:00:11,840 to, somewhat arbitrarily, paste it below the form my body. 5 00:00:11,840 --> 00:00:15,430 Notice here that I first included in my page's head a script tag, the 6 00:00:15,430 --> 00:00:19,790 source of which is the URL of jQuery, that popular JavaScript library. 7 00:00:19,790 --> 00:00:23,130 Below that is another script tag inside of which is my own code. 8 00:00:23,130 --> 00:00:28,060 In this first line of code, I specify, using jQuery that I'd like to execute 9 00:00:28,060 --> 00:00:33,050 the following anonymous function when the so-called document is ready. 10 00:00:33,050 --> 00:00:37,450 >> Specifically, I would like to first get the element from the page whose 11 00:00:37,450 --> 00:00:40,540 unique ID is registration, that is my form. 12 00:00:40,540 --> 00:00:44,380 I'd like to register an event handler for the form submission and execute 13 00:00:44,380 --> 00:00:47,950 the following anonymous function whenever that event triggered. 14 00:00:47,950 --> 00:00:53,230 Specifically, I'd like to get using jQuery, the element, whose unique 15 00:00:53,230 --> 00:00:59,070 identifier is registration, but from there grab the child of type input 16 00:00:59,070 --> 00:01:04,680 that happens I have an attribute called name whose value is email. 17 00:01:04,680 --> 00:01:08,430 >> Once done, I'd like to get the value that the user has provided for that 18 00:01:08,430 --> 00:01:13,530 form field and check does it equal quote unquote with nothing in between. 19 00:01:13,530 --> 00:01:16,920 If so, I'd like to yell at the user that he or she must provide their 20 00:01:16,920 --> 00:01:18,100 email address. 21 00:01:18,100 --> 00:01:21,990 >> Meanwhile I'd like to do something similar, checking whether that form, 22 00:01:21,990 --> 00:01:26,210 whose idea is registration, has an input field as a child, that has a 23 00:01:26,210 --> 00:01:28,430 name attribute whose value is password. 24 00:01:28,430 --> 00:01:33,160 And check, too, if the user's value for that is, quote unquote, "nothing." 25 00:01:33,160 --> 00:01:36,440 If so, I'd like to yell at the user, emphasizing that he or she must 26 00:01:36,440 --> 00:01:37,860 provide a password. 27 00:01:37,860 --> 00:01:41,890 >> Meanwhile, I'd also like to check if that form whose ID is registration, 28 00:01:41,890 --> 00:01:46,810 has an input child whose name attribute equals password, has a value 29 00:01:46,810 --> 00:01:51,970 that does not equal the value that the user has typed in for the field that's 30 00:01:51,970 --> 00:01:56,050 that similarly structured, but whose name is confirmation. 31 00:01:56,050 --> 00:02:00,330 If so, I want to yell at the user that his or her passwords do not match. 32 00:02:00,330 --> 00:02:04,770 >> Lastly, let's check if the registration form's input, whose name 33 00:02:04,770 --> 00:02:07,300 is agreement, is checked. 34 00:02:07,300 --> 00:02:11,900 And if so, let's negate that answer with bang and then yell at the user 35 00:02:11,900 --> 00:02:15,220 that he or she must agree to the terms and conditions. 36 00:02:15,220 --> 00:02:19,260 >> In each of these cases when the user has erred, we return false to prevent 37 00:02:19,260 --> 00:02:21,780 the form submission to register.php. 38 00:02:21,780 --> 00:02:25,660 Else, if no mistakes have been made, we instead return true, thereby 39 00:02:25,660 --> 00:02:29,590 indicating that the form should indeed be submitted to register.php. 40 00:02:29,590 --> 00:02:31,640 >> Let's take a look in a browser. 41 00:02:31,640 --> 00:02:32,850 Here then is my form. 42 00:02:32,850 --> 00:02:34,440 Let's try to register with nothing. 43 00:02:34,440 --> 00:02:37,340 But nope, I must provide my email address. 44 00:02:37,340 --> 00:02:39,360 Let's do so. 45 00:02:39,360 --> 00:02:42,080 >> Registering again yields that I must provide a password. 46 00:02:42,080 --> 00:02:45,090 Let's do so, this time providing crimson. 47 00:02:45,090 --> 00:02:48,570 >> Passwords do not match because, indeed, I've not confirmed by typing 48 00:02:48,570 --> 00:02:50,050 crimson again. 49 00:02:50,050 --> 00:02:53,590 And now I must agree to the terms and conditions by checking this box, 50 00:02:53,590 --> 00:02:55,500 followed by one final register. 51 00:02:55,500 --> 00:02:58,070 >> And now I am really, well not really, registered. 52 00:02:58,070 --> 00:03:00,054