Javascript DOM HTML Input URL defaultValue Property get

Introduction

Get the default value of a URL field:

var x = document.getElementById("myURL").defaultValue;

Click the button to display the default value of the URL field.

elements with type="url" are not supported in Safari.

View in separate window

<!DOCTYPE html>
<html>
<body>

Homepage: <input type="url" id="myURL" value="http://www.google.com">
<button type="button" onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from w  w w  . j  a v a2  s .  c  om*/
  var x = document.getElementById("myURL").defaultValue;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related