HTML <button> name Attribute

HTMLWeb DevelopmentFront End Technology

The name attribute of the <button> element is used to set the name for a button. More than one button can have the same name, but we can submit different values from these buttons using the name attribute.

Following is the syntax −

<button name="btn_name">

Above, btn_name is the name of the button. Let us now see an example to implement the name attribute if the <button> element −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<form action="" method="get">
   Get the details of the employee:<br><br>
   <button name="details" type="submit" value="addr">Address</button>
   <button name="details" type="submit" value="ph">Phone</button>
   <button name="details" type="submit" value="appraisal">Appraisal %</button>
</form>
</body>
</html>

Output

In the above example, different values will get submitted even when the name of the buttons is the same i.e. “details” set as the button name−

<button name="details" type="submit" value="addr">Address</button>
<button name="details" type="submit" value="ph">Phone</button>
<button name="details" type="submit" value="appraisal">Appraisal %</button>
raja
Published on 20-Jun-2019 08:36:31
Advertisements