Form printing script

  • This is a Version 2 script.
  • Explorer 3 and QNX Voyager can't handle this script.
  • Escape gives no type for INPUT's without a TYPE attribute (that default to "text").
  •  

    A script that prints out the form structure for you, so you can keep track of which element has which number etc.

    As example I take the same form as on the example form and script page.

    Name
    Address
    City
    E-mail
    Why do you want to learn JavaScript? Dunno
    Because my boss told me to
    Generally interested
    It might come in useful
    How did you get to this site?
    I'd like additional information about oranges
    potatoes
    tomatoes
    blue whales

    This is the form:

    ElementNameTypeValue

    This is the script. Copy-paste it below your form in the same page.

    
    <TABLE BORDER=1><TR><TH>Element</TH><TH>Name</TH><TH>Type</TH><TH>Value</TH>
    
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    
    for (var i=0;i<document.forms[0].length;i++)
    {
    	current = document.forms[0].elements[i];
    	document.write('<TR><TD>' + i);
    	document.write('<TD>' + current.name);
    	document.write('<TD>' + current.type);
    	document.write('<TD>' + current.value + '</TR>');
    }
    
    // -->
    </SCRIPT>
    
    </TABLE>
    
    

    Note document.forms[0].length: it is the number of elements in the form.

    Home