Change the default value of a URL field:
document.getElementById("myURL").defaultValue = "http://www.cnn.com";
Click the button to change the default value of the URL field.</p>
elements with type="url" are not supported in Safari.</p>
<!DOCTYPE html> <html> <body> Homepage: <input type="url" id="myURL" value="http://www.google.com"> <button type="button" onclick="myFunction()">Test</button> <script> function myFunction() {/* w w w. j a v a2s . c o m*/ document.getElementById("myURL").defaultValue = "http://www.cnn.com"; } </script> </body> </html>
The defaultValue property sets or gets the default value of a URL field.
The default value is the value specified in the HTML value attribute.
The defaultValue contains the default value, while value contains the current value.
Value | Description |
---|---|
value | Specifies the default value of the URL field |
The defaultValue property returns a String representing the default value of the URL field.