CSS Chapter 3 Test
CSS Chapter 3 Test
12. Write JavaScript code to count the number of input elements in a form.
13. Explain how to access and modify form elements using the
`getElementById` method.
15. How can you validate form elements before submission? Write an
example.
17. Explain how to change the placeholder text of a text field using
JavaScript.
18. How can you modify the `maxlength` attribute of an input field
dynamically?
2
22. Explain how to remove an option from a `<select>` dropdown using
JavaScript.
23. How can you sort the options in a `<select>` dropdown dynamically?
24. Write a JavaScript function that populates a city dropdown list based
on the selected state.
27. How can you retrieve the values of all selected checkboxes in a form?
29. Write a script that allows selecting all checkboxes in a form when a
"Select All" checkbox is checked.
30. How can you count the number of checkboxes selected by a user?
31. Write JavaScript code to change the text of a label when a button is
clicked.
3
33. How can you change the font size and color of a label dynamically using
JavaScript?
34. Write JavaScript to display the entered text dynamically as a label next
to the input field.
36. Write JavaScript code to enable or disable a text field based on user
selection.
37. How can you reset all input fields of a form using JavaScript?
38. Explain how to dynamically set focus to a specific form field when a
page loads.
39. Write a script to change the border color of a text field when an
incorrect value is entered.
40. How can you dynamically clone an input field using JavaScript?
41. Explain how the `parseInt()` and `parseFloat()` functions are used in
JavaScript.
44. How can you use the `isNaN()` function to validate numeric input
fields?
4
45. Write a JavaScript function to prevent a user from typing in a text field.