Javascript Form How to - Get Button NAME Property








Question

We would like to know how to get Button NAME Property.

Answer


<html>
    <form name="myForm">
      <input type="button"
             value="Press here to see the name of this button"
             name="myBigButton"
             onClick="displayButtonName()">
      <input type="text"
             name="textBox">
    </form>
    <script language="JavaScript">
    function displayButtonName()<!--from   w ww  .j av a2  s . co  m-->
    {
      document.myForm.textBox.value=document.myForm.myBigButton.name;
    }
    </script>
</html>

The code above is rendered as follows: