Create the nameSearch variable equal to the value entered in the nameSearch input box. Users can search for names in three ways: Matching an employee's last name if it contains the text string specified in nameSearch Matching an employee's last name if it begins with the nameSearch text string Matching an employee's last name only if it exactly matches the nameSearch text string. Richard has supplied you with code to add the selectedValue() method to the prototype of the HTMLSelectElement object class in order to return the value of the selected option in any selection list. Apply the selectedValue() method to the nameSearchType selection list to return the option selected by the user, storing the value in the nameSearchType variable. Create a switch-case structure for the following possible values of the nameSearchType
(this question is part 2 of 3 in a long problem)
JavaScript Commands
Create the nameSearch variable equal to the value entered in the nameSearch input box.
Users can search for names in three ways:
- Matching an employee's last name if it contains the text string specified in nameSearch
- Matching an employee's last name if it begins with the nameSearch text string
- Matching an employee's last name only if it exactly matches the nameSearch text string.
Richard has supplied you with code to add the selectedValue() method to the prototype of the HTMLSelectElement object class in order to return the value of the selected option in any selection list. Apply the selectedValue() method to the nameSearchType selection list to return the option selected by the user, storing the value in the nameSearchType variable.
Create a switch-case structure for the following possible values of the nameSearchType variable:
- If nameSearchType equals "contains", use the new RegExp() constructor to create a regular expression object named nameRegExp containing the regular expression nameSearch where nameSearch is the value of the nameSearch variable. Include the "i" flag with the regular expression object so that the regular expression matches lower or uppercase characters.
- If nameSearchType equals "beginsWith", set nameRegExp object to the regular expression ^nameSearch, once again with the "i" flag.
If nameSearchType equals "exact", set nameRegExp object to the regular expression ^nameSearch$ with the "i" flag to allow for upper- and lower-case matches.
cc_staff.js (add code to this file)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images