HTML Questions & Answers – Input Types for Forms

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Input Types for Forms”.

1. What is the default type of ‘type’ attribute of <input> element?
a) Text
b) Password
c) Numerals
d) Special Characters
View Answer

Answer: a
Explanation: Text input type defines single line text field. Type is the attribute that displays type of <input> elements. Its default type is text. It is supported by most of the browsers like Chrome, Internet Explorer, Firefox, Opera. Syntax is: <form action=”jump.php”> Name:<input type=”text” name=”name”> </form> A password field is defined by password input.

2. Which of the following is a new input attribute introduce by HTML5?
a) text
b) checkbox controls
c) submit buttons
d) date
View Answer

Answer: d
Explanation: HTML4 has attributes with <input> elements like radio buttons, Checkbox controls, submit buttons, text input etc.
HTML5 has introduced new attributes like date, color, month, time, week, datetime-local, email, number, range, tel, url, search etc.

3. How does the color attribute work?
a) Changes color of the text
b) Changes background color
c) The color picker is defined by it
d) Changes color of the text as well as background
View Answer

Answer: c
Explanation: color is the attribute of <input> element introduce by HTML5. It defines the color picker i.e we can select a color of our choice from the color picker. Syntax is Select the color that you want: <input type=”color” name=”favorite color”>
advertisement
advertisement

4. Which attribute is used for activation of JavaScript?
a) button
b) checkbox
c) url
d) submit
View Answer

Answer: a
Explanation: Input type button is used for the activation of JavaScript on the clicking of the button. Its syntax is <input type=”button” value=”click” onclick=”source()”>. This will display a button named click and when we click that button JavaScript function source() will be invoked.

5. Which attribute defines the file-select field?
a) file
b) checkbox
c) button
d) text
View Answer

Answer: a
Explanation: file input type defines a file-select field, also gives a “Browse” button for file uploads. Syntax is <input type=”file” name=”image”>. Checkbox gives the facility to select one or more than one options from the given choices. The button activates JavaScript code. The text defines a single-line text field.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. How image attribute works?
a) Sets an image background
b) Set an image as submit button
c) Set an image anywhere on the page
d) Bring default image to the page
View Answer

Answer: b
Explanation: the image input type set an image as submit button. The syntax is <input type=”image” src=”imghj.gif” alt=”Submit”> this sets the image provided by url as the submit button. Input type image sends the X and Y coordinates of click and hence the image is activated by clicking the submit button.

7. month attribute defines ___________
a) the only month
b) month and year
c) date
d) date and time
View Answer

Answer: b
Explanation: month and year are defined by month attribute. It does not define the time zone. The syntax is Anniversary (month and year) <input=”month” name=”anniversary month” >., date attribute defines the date, datetime-local defines date and time but no time zone.
advertisement

8. week attribute defines ____________
a) week
b) year
c) week and year
d) week, month and year
View Answer

Answer: c
Explanation: week input type defines a week and year. It does not define the time zone. Syntax is <form action=”ghu.php”> week: <input type=”week” name=”week and year”> <input type=”submit”> </form>, this gives a selection box and display a calendar like chart from where we can select a week and the year as well.

9. tel attribute is supported by the _________ browser.
a) Chrome
b) Safari
c) Opera
d) Internet Explorer
View Answer

Answer: b
Explanation: tel is the attribute which specifies field for telephone number. Syntax is <form action=”hkjk.php”> Telephone number: <input type=”tel” name=”usertelephone”> <br> <input type=”submit”> </form>, tel attribute is usually supported by newer versions like Safari 8.
advertisement

10. Which attribute is not used on new forms?
a) size
b) text
c) name
d) maxlength
View Answer

Answer: a
Explanation: size attribute denotes the width of text input i.e measured by the number of characters inputted. E.g. If we input value 3 then it will create a box of width enough to display three characters. The user can enter more characters if they want. Syntax is <input type=”text” name=”firstname” size=”12” maxlength=”30”>

11. Which of the following is not used with password attribute?
a) name
b) size
c) maxlength
d) min
View Answer

Answer: d
Explanation: password is the attribute that creates a text box which is similar to the single line text input, but the characters are blocked out. They are hidden due to the privacy of the user. The name attribute with a password set the name of the password input, size and maxlength attributes define the size and maximum length of the text box which is to be used for the password.

12. Which element is used to create multi-line text input?
a) text
b) textarea
c) submit
d) radio button
View Answer

Answer: b
Explanation: For creating multi-line text input we use <textarea> element. This is not empty element i.e. it requires both opening tag and closing tag. The cols attribute defines a width of the text area. The row attributes the number of rows that the textarea can require.

13. Which attribute is not used for the radio type?
a) name
b) value
c) checked
d) selected
View Answer

Answer: d
Explanation: When we want to pick one option from the given many options we use radio type. Name attribute sent the value of the option selected to the server. Value attribute indicates the value that has been sent to the server for the selected option. The checked attribute indicates that which value should be selected on the loading of the page.

14. Which attribute is used with <select> element?
a) multiple
b) selected
c) name
d) value
View Answer

Answer: a
Explanation: <select> element is used for drop down select box. Size attribute is used for showing more than one option. For a selection of multiple options, we use multiple attributes. It is a useful option to select multiple things at a time.
Syntax is

<form action=”jhi.php”> <select name=”fruits” size=5multiple=multiple”>

Sanfoundry Global Education & Learning Series – HTML.

To practice all areas of HTML, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.