Javascript DOM HTML Input URL Object get

Introduction

The Input URL object represents an HTML <input> element with type="url".

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

We can access an <input> element with type="url" via document.getElementById():

var x = document.getElementById("myUrl");

Click the button to get the URL 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 onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from   w  w  w. java 2 s  . c o  m*/
  var x = document.getElementById("myURL").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related