HTML DOM Samp Object

Samp Object The Samp object represents an HTML <samp> element. Access a Samp Object You can access a <samp> element by using getElementById(): Example var x = document.getElementById(“mySamp”); Try it Yourself » Create a Samp Object You can create a <samp> element by using the document.createElement() method: Example var x = document.createElement(“SAMP”); Try it Yourself » Standard […]

HTML <input> step Attribute

Example An HTML form with an input field with a specified legal number intervals: <form action=”/action_page.php”> <input type=”number” name=”points” step=”3″> <input type=”submit”> </form> Try it Yourself » Definition and Usage The step attribute specifies the legal number intervals for an <input> element. Example: if step=”3″, legal numbers could be -3, 0, 3, 6, etc. Tip: The step attribute can be used […]

HTML <input> src Attribute

Example An HTML form with an image that represents the submit button: <form action=”/action_page.php”> First name: <input type=”text” name=”fname”><br> <input type=”image” src=”submit.gif” alt=”Submit”> </form> Try it Yourself » Definition and Usage The src attribute specifies the URL of the image to use as a submit button. Note: The src attribute is required for <input type=”image”>, and can only be used with <input type=”image”>. […]

HTML <input> size Attribute

Example An HTML form with two input fields with a width of 35 and 4 characters: <form action=”/action_page.php”> Email: <input type=”text” name=”email” size=”35″><br> PIN: <input type=”text” name=”pin” maxlength=”4″ size=”4″><br> <input type=”submit” value=”Submit”> </form> Try it Yourself » Definition and Usage The size attribute specifies the visible width, in characters, of an <input> element. Note: The size attribute works with the following input types: text, search, tel, url, email, […]

HTML <input> required Attribute

Example An HTML form with a required input field: <form action=”/action_page.php”> Username: <input type=”text” name=”usrname” required> <input type=”submit”> </form> Try it Yourself » Definition and Usage The required attribute is a boolean attribute. When present, it specifies that an input field must be filled out before submitting the form. Note: The required attribute works with the following input types: text, search, url, […]

HTML <input> readonly Attribute

Example An HTML form with a read-only input field: <form action=”/action_page.php”> Country: <input type=”text” name=”country” value=”Norway” readonly><br> <input type=”submit” value=”Submit”> </form> Try it Yourself » Definition and Usage The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy […]

HTML <input> placeholder Attribute

Example Two input fields with a placeholder text: <form action=”/action_page.php”> <input type=”text” name=”fname” placeholder=”First name”><br> <input type=”text” name=”lname” placeholder=”Last name”><br> <input type=”submit” value=”Submit”> </form> Try it Yourself » Definition and Usage The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed […]

HTML <input> pattern Attribute

Example An HTML form with an input field that can contain only three letters (no numbers or special characters): <form action=”/action_page.php”> Country code: <input type=”text” name=”country_code” pattern=”[A-Za-z]{3}” title=”Three letter country code”> <input type=”submit”> </form> Try it Yourself » More “Try it Yourself” examples below. Definition and Usage The pattern attribute specifies a regular expression that the <input> element’s value is checked […]

HTML <input> name Attribute

Example An HTML form with three input fields; two text fields and one submit button: <form action=”/action_page.php”> Name: <input type=”text” name=”fullname”><br> Email: <input type=”text” name=”email”><br> <input type=”submit” value=”Submit”> </form> Try it Yourself » Definition and Usage The name attribute specifies the name of an <input> element. The name attribute is used to reference elements in a JavaScript, or to reference form data after a […]

HTML <input> multiple Attribute

Example A file upload field that accepts multiple values: <form action=”/action_page.php”> Select images: <input type=”file” name=”img” multiple> <input type=”submit”> </form> Try it Yourself » Definition and Usage The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input […]

HTML <input> value Attribute

Example An HTML form with initial (default) values: <form action=”/action_page.php”> First name: <input type=”text” name=”fname” value=”John”><br> Last name: <input type=”text” name=”lname” value=”Doe”><br> <input type=”submit” value=”Submit form”> </form> Try it Yourself » Definition and Usage The value attribute specifies the value of an <input> element. The value attribute is used differently for different input types: For “button”, “reset”, and “submit” – it defines the text on the […]

HTML <input> width Attribute

Example Define an image as the submit button, with height and width attributes: <form action=”/action_page.php”> First name: <input type=”text” name=”fname”><br> Last name: <input type=”text” name=”lname”><br> <input type=”image” src=”img_submit.gif” alt=”Submit” width=”48″ height=”48″> </form> Try it Yourself » Definition and Usage The width attribute specifies the width of the <input> element. Note: The width attribute is used only with <input type=”image”>. Tip: Always specify both the height and width attributes for […]

HTML <input> max Attribute

Example Use of the min and max attributes: <form action=”/action_page.php”> Enter a date before 1980-01-01: <input type=”date” name=”bday” max=”1979-12-31″> Enter a date after 2000-01-01: <input type=”date” name=”bday” min=”2000-01-02″> Quantity (between 1 and 5): <input type=”number” name=”quantity” min=”1″ max=”5″> <input type=”submit”> </form> Try it Yourself » Definition and Usage The max attribute specifies the maximum value for an <input> element. Tip: Use the max attribute together with the min attribute to […]

HTML <input> min Attribute

Example Use of the min and max attributes: <form action=”/action_page.php”> Enter a date before 1980-01-01: <input type=”date” name=”bday” max=”1979-12-31″> Enter a date after 2000-01-01: <input type=”date” name=”bday” min=”2000-01-02″> Quantity (between 1 and 5): <input type=”number” name=”quantity” min=”1″ max=”5″> <input type=”submit”> </form> Try it Yourself » Definition and Usage The min attribute specifies the minimum value for an <input> element. Tip: Use the min attribute together with the max attribute to […]

HTML <input> list Attribute

Example An <input> element with pre-defined values in a <datalist>: <input list=”browsers”> <datalist id=”browsers”> <option value=”Internet Explorer”> <option value=”Firefox”> <option value=”Google Chrome”> <option value=”Opera”> <option value=”Safari”> </datalist> Try it Yourself » Definition and Usage The list attribute refers to a <datalist> element that contains pre-defined options for an <input> element. Browser Support The numbers in the table specify the first browser version that fully […]

HTML <input> height Attribute

Example Define an image as the submit button, with height and width attributes: <form action=”/action_page.php”> First name: <input type=”text” name=”fname”><br> Last name: <input type=”text” name=”lname”><br> <input type=”image” src=”img_submit.gif” alt=”Submit” width=”48″ height=”48″> </form> Try it Yourself » Definition and Usage The height attribute specifies the height of the <input> element. Note: The height attribute is used only with <input type=”image”>. Tip: Always specify both the height and width attributes for […]

HTML <input> formtarget Attribute

Example A form with two submit buttons, with different target windows: <form action=”/action_page.php”> First name: <input type=”text” name=”fname”><br> Last name: <input type=”text” name=”lname”><br> <input type=”submit” value=”Submit as normal”> <input type=”submit” formtarget=”_blank” value=”Submit to a new window”> </form> Try it Yourself » Definition and Usage The formtarget attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form. […]

HTML <input> formnovalidate Attribute

Example A form with two submit buttons (with and without validation): <form action=”/action_page.php”> E-mail: <input type=”email” name=”userid”><br> <input type=”submit” value=”Submit”><br> <input type=”submit” formnovalidate=”formnovalidate” value=”Submit without validation”> </form> Try it Yourself » Definition and Usage The novalidate attribute is a boolean attribute. When present, it specifies that the <input> element should not be validated when submitted. The formnovalidate attribute overrides the novalidate attribute of the <form> element. […]

HTML <input> formmethod Attribute

Example The second submit button overrides the HTTP method of the form: <form action=”/action_page.php” method=”get”> First name: <input type=”text” name=”fname”><br> Last name: <input type=”text” name=”lname”><br> <input type=”submit” value=”Submit”> <input type=”submit” formmethod=”post” value=”Submit using POST”> </form> Try it Yourself » Definition and Usage The formmethod attribute defines the HTTP method for sending form-data to the action URL. The formmethod attribute overrides the method attribute of the <form> element. Note: The formmethod attribute […]

HTML <input> formenctype Attribute

Example Send form-data that is default encoded (the first submit button), and encoded as “multipart/form-data” (the second submit button): <form action=”/action_page_binary.asp” method=”post”> First name: <input type=”text” name=”fname”><br> <input type=”submit” value=”Submit”> <input type=”submit” formenctype=”multipart/form-data” value=”Submit as Multipart/form-data”> </form> Try it Yourself » Definition and Usage The formenctype attribute specifies how the form-data should be encoded when submitting it to the server (only for forms with method=”post”) […]