Javascript DOM HTML Input URL name Property get

Introduction

Get the name of a URL field:

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

Click the button to display the value of the name attribute 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" name="website">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

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

</body>
</html>

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

The name attribute can identify form data after submitting to the server.

Only form elements with a name attribute will be passed to the server.

Value Description
name Specifies the name of the URL field

The name property returns a String representing the name of the URL field.




PreviousNext

Related