
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input URL required Property
The Input URL required property determines whether Input URL is compulsory to set or not.
Syntax
Following is the syntax −
- Returning boolean value - true/false
inputURLObject.required
- Setting required to booleanValue
inputURLObject.required = booleanValue
Boolean Values
Here, “booleanValue” can be the following −
booleanValue | Details |
---|---|
True | It is compulsory to set the url field to submit form. |
False | It is the default value and to set an url field is not compulsory. |
Example
Let us see an example for Input URL required property −
<!DOCTYPE html> <html> <head> <title>Input URL required</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>URL-required</legend> <label for="URLSelect">URL: <input type="url" id="URLSelect" required> </label><br> <input type="button" onclick="showMessage()" value="Go"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputURL = document.getElementById("URLSelect"); function showMessage() { if(inputURL.required === true && inputURL.value === '') divDisplay.textContent = 'Cannot Redirect: URL is Required'; else divDisplay.textContent = 'Redirecting...'; } </script> </body> </html>
Output
This will produce the following output −
Clicking ‘Go’ button −
After clicking ‘Go’ button with value of an url field set −
- Related Articles
- HTML DOM Input URL autocomplete Property
- HTML DOM Input URL autofocus Property
- HTML DOM Input URL defaultValue Property
- HTML DOM Input URL disabled Property
- HTML DOM Input URL form Property
- HTML DOM Input URL maxLength Property
- HTML DOM Input URL name Property
- HTML DOM Input URL pattern Property
- HTML DOM Input URL placeholder Property
- HTML DOM Input URL readOnly Property
- HTML DOM Input URL size Property
- HTML DOM Input URL type Property
- HTML DOM Input URL value Property
- HTML DOM Input FileUpload required Property
- HTML DOM Input Month required Property

Advertisements