LAB 3.3 Flashcards

1
Q
  • specifies the URL where the form data should be submitted when the form is submitted.
A

action attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • assigns a name to the form. This name can be used to reference the form in JavaScript or to access form data on the server-side.
A

name attribute:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • This attribute specifies a JavaScript function to be executed when the form is submitted. In this case, it’s set to validateForm().
  • The return keyword before the function call ensures that the form submission is dependent on the return value of the validateForm() function.
  • If the function returns false, the form submission will be prevented; if it returns true, the form will be submitted.
A

onsubmit attribute:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

This declares a JavaScript function named validateForm(). This function will be called when the form is submitted, as specified in the onsubmit attribute of the <form> element

A

Function Declaration:
function validateForm() { … }:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • var firstName = document.forms[“form”][“firstName”].value;: This line retrieves the value entered into the “First Name” field of the form. It accesses the form using its name attribute (“form”) and then retrieves the value of the input field with the name attribute “firstName”.
  • Similar lines exist for retrieving values from other form fields such as “Last Name”, “Email”, “Password”, and “Re-type Password”. These values are stored in respective variables (lastName, email, password, retypePassword).
A

Variable Declarations:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • This if statement checks if any of the required fields (First Name, Last Name, Email, Password, and Re-type Password) are empty.
  • It uses the logical OR (||) operator to combine multiple conditions. If any of the conditions are true (i.e., if any of the fields are empty), the overall condition evaluates to true.
  • If the condition is true (i.e., if any field is empty), an alert is displayed to the user indicating that all fields must be filled out, and false is returned to prevent the form from being submitted.
A

Empty Field Check

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • This if statement checks if the password entered by the user matches the re-typed password.
  • It compares the password variable (containing the value of the password field) with the retypePassword variable (containing the value of the re-type password field) using the inequality operator (!=).
  • If the passwords do not match, an alert is displayed to the user indicating that the passwords do not match, and false is returned to prevent the form from being submitted.
A

Password Matching Check:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • var regex = /^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/;: This line creates a regular expression object named regex.
  • ^: Asserts the start of the string.
  • (?=.*\d): Positive lookahead assertion. Requires at least one digit (\d) to be present anywhere in the string
  • (?=.*[a-z]): Positive lookahead assertion. Requires at least one lowercase letter ([a-z]) to be present anywhere in the string.
  • (?=.*[A-Z]): Positive lookahead assertion. Requires at least one uppercase letter ([A-Z]) to be present anywhere in the string.
  • [0-9a-zA-Z]{8,}: Matches any alphanumeric character (0-9, a-z, A-Z) and ensures that the length is at least 8 characters.
  • $: Asserts the end of the string. Ensures the string matches the pattern from start (^) to end ($).
A

Regular Expression:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • if (!regex.test(password)) {:
  • This line checks if the provided password (password) matches the regular expression pattern defined by regex.
  • The test() method of the regular expression object checks whether the pattern matches the given string.
  • The ! operator negates the result, so the condition is true if the password does not match the pattern.
  • If the password does not match the pattern, it means the password does not meet the specified criteria (at least 8 characters long, including at least one number, one uppercase letter, and one lowercase letter).
  • An alert is displayed to inform the user about the password requirements.
  • return false;: This statement prevents the form from being submitted by returning false. If the password does not meet the criteria, the form submission is halted.
A

Password Validation Check:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly