You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > input:search

input:search object

Browser support:
Creates a search field. It contains a single-line text input control with a search history dropdown list.
All searches in this field are saved into the search history under the category specified by the autosave attribute. If the autosave attribute of two different search tags contain identical values, the searches belonging to these fields are saved under the same category of the history.
Use a unique category name (for example, the domain where the site is) to avoid the mixing of categories. If the autosave attribute is not defined, then the history dropdown list is invisible, and the searches are not saved into the history.
The results attribute specifies how many elements are visible in the dropdown list of the search history.
This control is one of the form controls.
The contents of the control can be submitted to a server if the following conditions are met:
  • A form element must contain the search control.
  • The action property of the container form must be set to the URL of the server.
  • The name property of the search control must be specified and non-empty.
When the container form is submitted, the name and the text content of the control are sent as a name/value pair.
You can access the text content of the control with the value property. Sometimes it is useful to check the contents before submitting. See Example 2 for details.

Syntax:

Methods that return the object:
var inputObj = document.createElement ("input");   inputObj.type = "search"
The base interface, through which you can add new functionalities to the input:search object, is the HTMLInputElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: input:search

Possible members:

Properties
Methods
Events
Style properties
accessKey
Sets or retrieves an access key to an element.
attributes
Represents a collection of attribute nodes that belong to an element.
baseURI
10
Returns the base URL for the object.
className
Sets or retrieves the style class or classes that belong to the element.
clientHeight
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, but it does not include the scrollBar, border, and the margin.
clientLeft
Returns the width of the left border in pixels.
clientTop
Returns the height of the top border in pixels.
clientWidth
Returns the width of the visible area for an object, in pixels. The value contains the width with the padding, but does not include the scrollBar, border, and the margin.
contentEditable
Sets or retrieves whether the contents of the object are editable.
defaultValue
Specifies or returns the initial value of the object. The initial state can be set with the value attribute in HTML.
dir
Sets or retrieves the text direction as related to the lang property.
disabled
Sets or retrieves the state of an object for user interaction.
form
Returns a reference to the form element in which the object is placed.
id
Sets or retrieves a unique identifier for the object.
isContentEditable
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
lang
Specifies or returns the language of the element.
localName
Returns the local part of the qualified name of the current node.
name
Sets or retrieves the name of a form control that affects the contents of the message submitted to the server.
namespaceURI
Sets or returns the namespace URI of the current node.
nextElementSibling
Returns a reference to the next child element of the current element's parent.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeValue
Sets or returns the value of the current node.
offsetHeight
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
offsetLeft
Returns the left position of an object relative to the left side of its offsetParent element, in pixels.
offsetParent
Returns a reference to the closest ancestor element in the DOM hierarchy from which the position of the current element is calculated.
offsetTop
Returns the top position of the object relative to the top side of its offsetParent element, in pixels.
offsetWidth
Returns the width of the visible area for an object, in pixels. The value contains the width with the padding, scrollBar, and the border, but does not include the margin.
outerHTML
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
placeholder
Sets or retrieves the initial value of the text field.
previousElementSibling
Returns a reference to the previous child element of the current element's parent.
previousSibling
Returns a reference to the previous node of the current element's parent.
readOnly
Sets or retrieves whether the contents of the element are changeable.
selectionEnd
Specifies or returns the end position of the selected text within the current element.
selectionStart
Specifies or returns the start position of the selected text within the current element.
size
Specifies or returns the width of a control, in characters.
style
Represents the inline style settings for an element or a CSS rule.
tabIndex
Specifies or returns the tabbing order for keyboard navigation using the TAB key.
tagName
Returns the tag name of the current element.
title
Specifies or returns a tooltip for an element.
type
Sets or retrieves the type of the input element.
value
Specifies or returns the value of the control.

Example HTML code 1:

This example illustrates the use of the search input element:
<form method="post" action="#URL#">
    Search for: <input type="search" name="search" autosave="www.dottoro.com" results="10" />
    <br /><br />
    <input type="submit" value="Search" />
</form>
Did you find this example helpful? yes no

Example HTML code 2:

This example checks the contents of the search input element before submitting the form:
<head>
    <script type="text/javascript">
        function CheckAndSubmit () {
            var searchForm = document.getElementById ("searchForm");
            var searchField = document.getElementById ("searchField");

            if (searchField.value.length == 0) {
                alert ("Please specify the word to search!");
                return;
            }

            searchForm.submit ();
        }
    </script>
</head>
<body>
    <form id="searchForm" method="post" action="#URL#">
        What to find: <input type="search" name="search" id="searchField" autosave="www.dottoro.com" results="10" />
        <br /><br />
        <input type="button" value="Search" onclick="CheckAndSubmit ()" />
    </form>
</body>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content