Javascript Form How to - Get Button value property which is read-only string displayed in graphical button








Question

We would like to know how to get Button value property which is read-only string displayed in graphical button.

Answer


<!-- ww  w  .  j a v a 2s .com-->
<html>
    <form name="myForm">
      Please enter your name:
      <input type="text"
             name="nameBox">
      <input type="button"
             name="customizeTheButton"
             value="Customize the button"
             onClick="customizeButton()"><HR>
      <input type="button"
             name="theButton"
             value="Press"
             onClick="displayconsole.log()">
    </form>
    <SCRIPT LANGUAGE="JavaScript">
    function customizeButton()
    {
      var aString = document.myForm.nameBox.value;
      aString += " press this button!";
      document.myForm.theButton.value=aString;
    }
    function displayconsole.log()
    {
      console.log("You pressed the button.");

    }
    </script>
</html>

The code above is rendered as follows: