Input URL name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input URL

Description

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

Set the name property with the following Values

Value Description
name Sets the name of the URL field

Return Value

A String, representing the name of the URL field

The following code shows how to get the name of a URL field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" name="website">

<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myURL").name;
    console.log("The name of the URL field is: " + x);
}

function change() {//ww w.  ja v a2  s .com
    var x = document.getElementById("myURL").name = "newNameValue";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials