forms Flashcards
Name the attributes of form in HTML5.
autocomplete and novalidate
Give any three input attributes’ names.
autocomplete autofocus form formaction formenctype formmethod formnovalidate formtarget height and width list min and max multiple pattern (regexp) placeholder required step
Is input attribute “form” supported in IE?
It is not supported in IE.
Which web browsers support the input attribute “autofocus”?
Input attribute “autofocus” is supported by Firefox, Opera and Chrome.
Does Opera support the input attribute “novalidate”?
Starting from version 11, Opera supports the input attribute “novalidate”.
What does autocomplete attribute do?
he autocomplete attribute specifies that the form or input field should have an autocomplete function.
You have a form with multiple fields. You wish to automatically get focus on a field when a page gets loaded. Which field attribute will you use?
The autofocus attribute will be used.
e.g. ‹form›
‹input name=”q” autofocus›
‹input type=”submit” value=”Search”› ‹/form›
Does autofocus attribute work with all input types?
Yes, autofocus attribute works with all input types.
What does form attribute do?
The form attribute is used to specify one or more forms.
Give an example of form attribute.
‹form action=”from1.asp” method=”get” id=”form1”›
First name:‹input type=”text” name=”fname” /› ‹input type=”submit” /›
What does form override attribute do?
Some of the attributes set for the form element can be overridden using override attribute.
Explain the types of override attributes.
a) formaction - overrides the form action attribute
b) formenctype - overrides the form enctype attribute
c) formmethod - overrides the form method attribute
d) formnovalidate - overrides the form novalidate attribute e) formtarget - overrides the form target attribute
What is the main function of the override attribute types?
Override attribute types are helpful for creating different submit buttons.
Which attributes can be used to specify the dimensions of an image used for the input type image?
The height and width attributes specify the height and width of the image used for the input type image.
Give an example of input type image using width and height attributes.
‹input type=”image” src=”img_submit.gif” width=”24” height=”24” /›
What does a list attribute do?
The list attribute specifies a datalist for an input field.
[input list=”browsers”]
[datalist id="browsers"] [option value="Internet Explorer"] [option value="Firefox"] [option value="Chrome"] [option value="Opera"] [option value="Safari"] [/datalist]
Name the input attribute’s types with which the attribute “list” works.
The list attribute works with the input types namely text, search, url, telephone, email, date pickers, number, range, and color.
How can you specify minimum and maximum value for an input field?
The min and max attributes of input field can be used to specify the minimum and maximum value for input field.
[form action=”demo_form.asp”]
Enter a date before 1980-01-01:
[input type=”date” name=”bday” max=”1979-12-31”]
Enter a date after 2000-01-01:
[input type=”date” name=”bday” min=”2000-01-02”]
Quantity (between 1 and 5):
[input type=”number” name=”quantity” min=”1” max=”5”]
[input type=”submit”]
[/form]
Which datatypes are compatible with input tag’s min and max attributes?
input tag’s min and max attributes work with numbers or dates.
What does step attribute do?
The step attribute is used to specify legal number intervals for the input field.
What will be the legal allowed values for the following?‹input type=”number” name=”points” min=”0” max=”10” step=”3” /›
0, 3, 6.9
Give an example which shows a numeric field that accepts values between 0 and 10, with a step of 3.
Points: ‹input type=”number” name=”test” min=”0” max=”10” step=”3” /›
Which attribute specifies that multiple values can be selected for an input field?
The multiple attribute
With which input types does the multiple attribute work?
The multiple attribute works with the input type file and email. e.g. Select: ‹input type=”file” name=”img” multiple=”multiple” /›
You have a form and you do not want any form validation over it. Which HTML5 attribute is to be used?
The novalidate attribute is used to submit not validated form data.
Will you prefer HTML5 form validation over JavaScript form validation? Why?
Yes. There are two reasons for this:
a) I have to write and maintain JavaScript form validation script.
b) If a user has disabled JavaScript on his web browser, then JavaScript form validation will be bypassed.
Will HTM5 form validation work on a compatible web browser if scripting is disabled?
Yes. The browser will do RFC-compliant email validation on form submission.
Given an example of a form that submits unvalidated data.
‹form action=”demo_form.asp” novalidate=”novalidate”›
E-mail: ‹input type=”email” name=”user_email” /›
‹input type=”submit” /› ‹/form›
What does a pattern attribute do?
The pattern attribute specifies a pattern used to validate an input field. A valid regular expression needs to be provided when using pattern attribute.
Name the input attribute types with which the attribute “pattern” works.
The pattern attribute works with the types: text, search, url, telephone, email, and password.
Give an example of pattern attribute.
In the following example, country code pattern is specified for validation. Country code: ‹input type=”text” name=”country_code” pattern=”[A-z]{3}” title=”Three letter country code” /›
What does a placeholder attribute do?
The placeholder attribute is used to provide a hint to the user about the expected value of an input field.
Name the input attribute types with which the attribute “placeholder” works.
The placeholder attribute works with the following types: text, search, url, telephone, email, and password.
What does a required attribute do?
A required attribute is a way to make a form field mandatory. User has to fill it in order to successfully submit the form.
Name the input attribute types with which the attribute “required” works.
The required attribute works with the following types: text, search, url, telephone, email, password, date pickers, number, checkbox, radio, and file.
Give an example to show the usage of required attribute.
The following example makes the input field mandatory.
You name: ‹input type=”text” name=”usr_name” required=”required” /›