|
<FORM ...>NAME = "text string"| Usage Recommendation |
|---|
NAMENAME
<SCRIPT>
<!--
function Circle_calc_ii()
{
var CircleRadius = document.MyCircleForm.Circle_radius.value;
if (CircleRadius >= 0)
{
document.MyCircleForm.Circle_circumference.value = 2 * Math.PI * CircleRadius ;
document.MyCircleForm.Circle_area.value = Math.PI * Math.pow(CircleRadius, 2) ;
}
else
{
document.MyCircleForm.Circle_circumference.value = "";
document.MyCircleForm.Circle_area.value = "";
}
}
// -->
</SCRIPT>
<FORM NAME="MyCircleForm">
<TABLE BORDER CELLPADDING=3>
<TR>
<TD><NOBR>radius: <INPUT NAME="Circle_radius" SIZE=4></NOBR></TD>
<TD><INPUT TYPE=BUTTON OnClick="Circle_calc_ii(this.form);" VALUE="calculate"></TD>
<TD ALIGN=RIGHT BGCOLOR="#AACCFF">
<NOBR>circumference: <INPUT NAME="Circle_circumference" SIZE=9></NOBR><BR>
<NOBR>area: <INPUT NAME="Circle_area" SIZE=9></NOBR></TD>
</TR>
</TABLE>
</FORM>
It is possible to refer to the form without using NAMEthis.form), obviating the need
for NAME
<FORM><!-- note there is no NAME atttibute -->
<TABLE BORDER CELLPADDING=3>
<!-- circumference and radius of a circle -->
<TR>
<TD><NOBR>radius: <INPUT NAME="Circle_radius" SIZE=4></NOBR></TD>
<TD><INPUT TYPE=BUTTON OnClick="Circle_calc(this.form);" VALUE="calculate"></TD>
<TD ALIGN=RIGHT BGCOLOR="#AACCFF">
<NOBR>circumference: <INPUT NAME="Circle_circumference" SIZE=9></NOBR><BR>
<NOBR>area: <INPUT NAME="Circle_area" SIZE=9></NOBR></TD>
</TR>
</TABLE>
</FORM>
which gives us
Another much worse way to refer to the form without giving it a name is to use the form's index in the forms array. If our form were the first form on this web page, we could refer to it like this:
var CircleRadius = parseFloat(document.forms[0].Circle_radius.value);
That would require keeping track of how many forms down on the page it is, and on a page like this that would be way too much trouble.
Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.