Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does document.form mean in javascript?

In JavaScript, what is the meaning of the identifiers document.cookie, document.forms and the .value field? I have trouble understanding the use of the below syntax example.

var x=document.forms["myForm"]["email"].value

Best wishes😀

like image 400
dramasea Avatar asked Jan 17 '11 15:01

dramasea


People also ask

What do you mean by document form?

A form is a document with spaces (also named fields or placeholders) in which to write or select, for a series of documents with similar contents. The documents usually have the printed parts in common, except, possibly, for a serial number.

Why is document used in JavaScript?

It allows a language (JavaScript) to manipulate, structure, and style your website. After the browser reads your HTML document, it creates a representational tree called the Document Object Model and defines how that tree can be accessed.

What is the purpose of form document?

A form is a structured document with a fixed arrangement. Forms are used to collect the required information in a logical, meaningful fashion for communication and pass to another entity.


1 Answers

document.forms["myForm"]["email"].value

that will get the value of the "email" element within the "myForm" <form>

<form id="myForm" name="myForm">
    <input id="email" name="email" value="[email protected]" />
</form>

so x will equal "[email protected]"


document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection

like image 174
hunter Avatar answered Oct 17 '22 21:10

hunter