程序代写 Presented by

Presented by

A HTML

element is a way of defining a form which is used to get user input

Copyright By PowCoder代写 加微信 powcoder

They consist of different types of input elements:
text fields checkboxes radio buttons submit buttons
We specify the type of input element using the type attribute:

First name:

Last name:

Reading forms in JavaScript

document.forms
When you have forms in your document, they can be found in a special document property
This is a ¡°named collection¡±, i.e. it¡¯s both named and ordered. We can use both the name or the number in the document to get the form.
document.forms.test // the form with name=”test”
document.forms[“test”] // also the form with name=”test”
document.forms[0] // the first form in the document
document.forms

form.elements
Each form has a field form.elements which has all of the elements in that form. This is also a ¡°named collection¡±



const form = document.forms[0];
// element with the name “fname”
form.elements.fname;
// shorter notation:
form.fname;
// since there are multiple elements with
the name “age”, this returns a collection
const ages = form.elements.age;

Backreferences
Each form element stores a backreference to the form it came from, element.form
Image source: javascript.info

Backreferences

const form = document.forms[0];
const login = form.login;
console.log(login.form)
What will this console.log?

Form Values
To get the value of a form element:
// To get the text for an input element or textarea:
input.value
// To get a boolean for a checkbox or radio button
input.checked
// For a

Forms Example

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com