Javascript DOM HTML Input URL value Property set

Introduction

Change the URL of a URL field:

document.getElementById("myURL").value = "http://www.cnn.com";

Click the button to change 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  .  j a va 2 s  . c o m
  document.getElementById("myURL").value = "http://www.cnn.com";
}
</script>

</body>
</html>

The value property sets or gets the value attribute of a URL field.

The value attribute specifies the default value OR the value a user types in.

The value property accepts and returns a String type value.




PreviousNext

Related