HTML: Sending the form
The last step in creating the form is to add a button to send the result to the server. To do this, use the paired <button> tag to create a submit button:
<form>
<button>Submit</button>
</form>After clicking on the "Submit" button, the data will be sent to the handler that is specified in the action attribute (if not specified, the data will be sent to the same page). The page will reload after you submit the data.
Now, using the form elements from the previous lessons, create a form with different fields.
<h2>Search form</h2>
<form>
<label>
Enter your query
<input type="search">
</label>
<select>
<option disabled>Choose section to search in</option>
<option>JS</option>
<option>HTML</option>
<option>CSS</option>
</select>
<button>Search</button>
</form>
If you click the "Search" button, the page will reload, and the data should go to the handler on the same page. Since there is no handler, there will be no visible results other than a page reload.
Instructions
Create a form with a data handler file at /people. Inside the form, add the following elements:
- Two
<input>text boxes - Multiple choice list
- "Submit" button
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
HTML: Sending the form
The last step in creating the form is to add a button to send the result to the server. To do this, use the paired <button> tag to create a submit button:
<form>
<button>Submit</button>
</form>After clicking on the "Submit" button, the data will be sent to the handler that is specified in the action attribute (if not specified, the data will be sent to the same page). The page will reload after you submit the data.
Now, using the form elements from the previous lessons, create a form with different fields.
<h2>Search form</h2>
<form>
<label>
Enter your query
<input type="search">
</label>
<select>
<option disabled>Choose section to search in</option>
<option>JS</option>
<option>HTML</option>
<option>CSS</option>
</select>
<button>Search</button>
</form>
If you click the "Search" button, the page will reload, and the data should go to the handler on the same page. Since there is no handler, there will be no visible results other than a page reload.
Instructions
Create a form with a data handler file at /people. Inside the form, add the following elements:
- Two
<input>text boxes - Multiple choice list
- "Submit" button
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Your exercise will be checked with these tests:
const { test } = require('tests');
test(({ query, expect }) => {
const form = query(document, 'form');
const select = form.querySelector('select');
const inputs = form.querySelectorAll('input');
const button = query(form, 'button');
expect(form).to.have.attr('action', '/people');
expect(select).to.be.visible;
expect(select).to.have.attr('multiple');
expect(inputs).to.have.length(2);
inputs.forEach((input) => {
expect(input).to.have.attr('type', 'text');
});
expect(button).to.be.visible;
});Teacher's solution will be available in:
20:00
