- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input URL value Property
The HTML DOM Input URL value property returns a string if value attribute is defined of input URL. User can also set it to a new string.
Syntax
Following is the syntax −
- Returning string value
inputURLObject.value
- Setting value attribute to a string value
inputURLObject.value = ‘String’
Example
Let us see an example for Input URL value property −
<!DOCTYPE html> <html> <head> <title>Input URL value</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-value</legend> <label for="URLSelect">URL Id: <input type="url" id="URLSelect"> <input type="button" onclick="getUserURL('google')" value="Google"> <input type="button" onclick="getUserURL('bing')" value="Bing"><br> <input type="button" onclick="redirection()" value="Go"> </label> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputURL = document.getElementById("URLSelect"); function getUserURL(userName) { if(userName === 'google') inputURL.value = 'https://www.google.com'; else inputURL.value = 'https://www.bing.com'; } function redirection() { if(inputURL.value !== '') divDisplay.textContent = 'Redirecting to '+inputURL.value; else divDisplay.textContent = 'Enter URL'; } </script> </body> </html>
Output
This will produce the following output −
Clicking ‘Go’ button with empty url field −
After clicking ‘Bing’ button −
After clicking ‘Go’ button with url field set −
Advertisements