html forms Flashcards

1
Q

What’s <form>?

hint

<form>
</form>

A

The <form> element is a great tool for collecting information.
We need to supply the <form> element with both the location of where the <form>‘s information goes and what HTTP request to make.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the action and the method attribute for?

A

The action attribute determines where the information is sent.
The method attribute is assigned a HTTP verb that is included in the HTTP request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create an input field in your <form> ?

A

Using the <input></input> element.
The <input></input> element has a type attribute which determines how it renders on the web page and what kind of data it can accept. e.g. type=”text”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

It’s also important that we include a name attribute for the <input></input>, why?

A

Without the name attribute, information in the <input></input> won’t be sent when the <form> is submitted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The value of the ‘value’ attribute is paired with the value of the name attribute and sent as text when the form is submitted..

A

e.g. <form action="/example.html" method="POST">
<input></input>
</form>
if you type “i won’t pay”
When the form is submitted, the text: “first-text-field= I won’t pay” is sent to /example.html.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you assign a default value for the ‘value’ attribute? if so, how?

A

Yes,
<input></input>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would a user properly identify an <input></input> element?

A

For a user to properly identify an <input></input> we use the appropriately named <label> element.</label>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you associate an <input></input> and a <label> element?
hint</label>

<form>
<label>What do you want to eat?</label>
<br></br>
<input></input>
</form>

A

To associate a <label> and an <input></input>, the <input></input> needs an id attribute.
We then assign the for attribute of the <label> element with the value of the id attribute of <input></input>.</label></label>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you input a password into a form so other people can’t see?

A

An <input></input> element will replace input text with another character like an asterisk () or a dot ().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create a form where you can only type numbers?
What does the step attribute do?

A

By setting type=”number” for an <input></input> we can restrict what users type into the input field to just numbers.
step attribute which creates arrows inside the input field to increase or decrease by the value of the step attribute. e.g. step=”1”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you create a slider?
(with <input></input>).

<form>
<label> Volume Control</label>
<input></input>
</form>

A

Firstly, you would set type=”range”.
You can use min= and max= to set the minimum and maximum amount.
We could also control how smooth and fluid the slider works by assigning the ‘step’ attribute a value.
The lower the number the more fluid the slider where as the bigger the number results in the slider moving more noticeably.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you create a checkbox?
(with <input></input>).
Make sure you use <label> per checkbox.</label>

A

In a <form> we would use the <input></input> element and set type=”checkbox”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

checkbox example:

<form>
<p>Choose your pizza toppings:</p>
<label>Extra cheese</label>
<input></input>
<br></br>
</form>

A

<label>Pepperoni</label>
<input></input>
<br></br>
<label>Anchovy</label>
<input></input>
</form>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you create a radio button?

<form>
<p>What is sum of 1 + 1?</p>
<input></input>
<label>2</label>
</form>

A

type=”radio”

<br></br>
<input></input>
<label>11</label>
</form>

To group radio buttons together, we assign them the same name and only one radio button from that group can be selected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would you create a dropdown list?

A

<form>
<label>What's for lunch?</label>
<select>
<option>Pizza</option>
<option>Curry</option>
<option>Salad</option>
<option>Ramen</option>
<option>Tacos</option>
</select>
</form>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you use the <datalist> element?</datalist>

A

<form>
<label>Ideal city to visit?</label>
<input></input>

<datalist>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</datalist>
</form>

17
Q

What is the <textarea> element used for?</textarea>

<form>
<label>New Blog Post: </label>
<br></br>
<textarea>
here is the default value</textarea>
</form>

A

The <textarea> element is used to create a bigger text field for users to write more text.
We can add the attributes rows and cols to determine the amount of rows and columns for the <textarea>.
If we want to add a default value to <textarea> we would include it within the opening and closing tags.</textarea></textarea></textarea>

18
Q

How would you create a submit button in a form?

A

To make a submit button in a <form>, we’re going to use the reliable <input></input> element and set the type to “submit”.

<form>
<input></input>
</form>