HTML Forms

type has button,checkbox,file,password,radio,reset,submit,text

select,select multiple, option

textarea

Selecting Forms and Form Elements

getElementById(), getElementByTagName()

Form and Element Properties

type form name value

Form and Element Event Handlers

Each Form element has an onsubmit event handler to detect form submission and an onreset event handler to detect form resets. The onsubmit handler is invoked just before the form is submitted; it can cancel the submission by returning false.

Note that the onsubmit handler is triggered only by a genuine click on a Submit button. Calling the submit() method of a form does not trigger the onsubmit handler.

The onreset event handler is similar to the onsubmit handler. It is invoked just before the form is reset, and it can prevent the form elements from being reset by returning

Push Buttons

Toggle Buttons

Text Fields

Select and Option Elements

Document.write()

document.write() concatenates its string arguments and inserts the resulting string into the document at the location of the script element that invoked it.

Quering Selected Text

The standard window.getSelection() method returns a Selection object that describes the current selection as a sequence of one or more Range objects.

Editable Content

Set the contenteditable HTML attribute of any tag or set the contenteditable JavaScript property on the corresponding Element to make the content of that element editable.

    <div id="editor" contenteditable> 
    Click to edit
    </div>

You can also make an entire document editable by setting the designMode property of the Document object to the string “on”. (Set it to “off” to revert to a read-only docu- ment.)

    <iframe id="editor" src="about:blank"></iframe> // Empty iframe <script>
    onLoad(function() { // When document loads,
    var editor = document.getElementById("editor"); // get the iframe document
    editor.contentDocument.designMode = "on"; // and turn editing on. });
    </script>