a <form>
is an HTML element that contains input elements
<form method='post'>
Name: <input type='text' name='name' value='Alice'>
<br />
Password: <input type='password' name='password'>
<br />
<input type='submit'>
</form>
<form>
element will correspond to a block element (viz. the border of the form)
<form>
is an inline elementdiv
form
alone<form method='get' action='/login'>
method
corresponds to the first word in the HTTP protocol
action
is the server path to submit the form to
GET
means "return me a page (based on these parameters)"POST
means "take these parameters (and return me a page)"Basically, GET
is for reading and POST
is for writing
but that distinction is often blurry
Also,
GET
sends all parameters via the request URL
POST
sends some or all parameters via the request body* <form method='GET' action='/search'>
<label>Search by Author: <input type="search" name="author"></label>
<input type='submit' value='Search'>
</form>
<label>
marks some text as belonging to a certain input element<input name='q' type='search'>
is a text field
<input type='submit' value='Search'>
is a button whose label is the string "Search"
There are many more types of form elements (or "widgets") that let the user enter data in a wide variety of formats.
<form href='#'>
in your HTMLevent.preventDefault();
in your JS event handlerform.submit()
on the form DOM elementq=apple&submit=Search
Forms are a great way to accept user input in your webpages. The simplest way to handle user input is to create a form with an <input type="text" />
element, and an <input type="submit" />
element.
When the form is submitted you use JavaScript to read the value of the text field, and do whatever manipulations, or actions you need to do based on that input.
In this lab you will set up an input form where you can enter a name, and the page will display text greeting that name.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form - docs https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms - guide
/