The formname property

The formname property is actually not a property itself but the property is the name of the form you create.

<body>
<form name="TheForm">
<input type="button" name="MyButton" value="Click if you are not afraid" />
</form>
</body>

The code creates a document.TheForm property from the name = "TheForm" attribute from the form tag which allows you to access the form elements within the form.

<body>
<form name="TheForm">
<input type="button" name="MyButton" value="Click if you are not afraid" 
onclick="document.TheForm.MyButton.value = 'Wow, you clicked, thanks!';"/>
</form>
</body>

The code accessed the form element first then the button within the form then the value of the button.
Now, when you click the button its value is changed.

Note:
It is recommended to access form elements by assigning an id to the form and using document.getElementById() method.

Leave a Reply