The name
attribute in form fieldset element
specifies the name of the field.
The name is used to reference form-data after it has been submitted, or to reference the element in a JavaScript.
The name
property sets or gets the value of the name attribute of a fieldset.
Fieldset name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
fieldsetObject.name
Set the name property.
fieldsetObject.name=name
Value | Description |
---|---|
name | Set the name of the fieldset |
A String type value representing the name of the fieldset.
The following code shows how to change the name attribute of a fieldset.
<!DOCTYPE html>
<html>
<body>
<form>
<fieldset id="myFieldset" name="information">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="usermail"><br>
</fieldset>
</form><!--from w w w.j a v a2 s. com-->
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myFieldset").name = "newName";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the value of the name attribute of a fieldset.
<!DOCTYPE html>
<html>
<body>
<!-- ww w . j av a2s .c o m-->
<form>
<fieldset id="myFieldset" name="information">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="usermail"><br>
</fieldset>
</form>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myFieldset").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: