Web Hosting Directory | Web Hosting Resources | Webmaster Resources | Domain Tools | Search Engine Marketing | Forums
  Signup
Today: 1,247   Yesterday: 1,015   Max: 1,872   Total: 464,300   Current Users : 16 (Member 0) 
DOMAIN TOOLS

WEBMASTER TOOLS

RELATED ARTICLES

SUBMIT AN ARTICLE

Write for us and get publicity, link to your website, and best of all get paid. Please visit our writers page for details.


LINK TO US

Link to us and earn points for each visitor you bring to us. Please visit our link partner page for details.

 

Attribute for <FORM ...>
NAME = "text string"

Usage Recommendation
thumbs up use it

NAME gives a name to the form. This is most useful in scripting, where you frequently need to refer to the form in order to refer to the element within the form. For example, this reduced version of our geometry calculating script uses NAME to refer to the form which holds the radius field:

<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>

radius: circumference:
area:

It is possible to refer to the form without using NAME, and sometimes it makes for less work. To give the above example we needed to create the whole script all over again. Instead, we could use the original CircleAreaCalc function at the top of this page, which allows us to pass in the form object as an argument (using this.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

radius: circumference:
area:

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. Written by Miko Sullivan.

 
 
 
What is your major source of website traffic?
 
 
 
 
 
 

ADVERTISEMENT

 
Cheap Web HostingBudget Web HostingEcommerce Web Hosting
Link to UsLink ExchangeAdvertisePrivacy PolicyTerms Of ServiceAbout UsContact UsSitemap
Copyright © 2006 - 2008 Broadband Media, Inc. All rights reserved.