Programming in HTML5 with JavaScript and CSS3 — Question 54

You are developing a customer web form that includes the following HTML.
<input id = "txtValue" />
A customer must enter a value in the text box prior to submitting the form.
You need to add validation to the text box control.
Which HTML should you use?

Answer options

Correct answer: A

Explanation

The correct answer is A because it uses the 'required' attribute, ensuring that the text box must be filled out before the form can be submitted. Option B only enforces a specific pattern and does not require an entry. Options C and D incorrectly use 'type' for 'required', which is not a valid input type, thus failing to provide the necessary validation.