Javascript Form How to - Get TextArea name, default value, value, type property








Question

We would like to know how to get TextArea name, default value, value, type property.

Answer


<html>
<head>
    <script language="JavaScript">
    function openWin(){<!--from  w ww .ja va 2 s.  c  o  m-->
      var myInstance = document.myForm.myTextArea;
      console.log("The defaultValue is: " + myInstance.defaultValue + "<br>");
      console.log("The name is: " + myInstance.name + "<br>");
      console.log("The type is: " + myInstance.type + "<br>");
      console.log("The value is: " + myInstance.value + "<br>");
      console.log(myInstance.form.myButton.value);
    }
    </script>
</head>
<body>
    <form name="myForm">
       <textarea name="myTextArea" rows=6 cols=50>
       Here is some text in my text area.
       </textarea>
       <input type=BUTTON value="Click to Process" name="myButton" onClick="openWin()">
    </form>
</body>
</html>

The code above is rendered as follows: