Can't get form with name attribute to validate in strict XHTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MikeinDC
    New Member
    • Oct 2006
    • 1

    Can't get form with name attribute to validate in strict XHTML

    I found some free js that I want to use in a class project.

    The original HTML used <form name="form1"> and the W3C validator I am required to use fails it. It says there is no attribute"name" . When I change it to <form id="form1"> the page validates but the js does not work.

    It will validate in Tidy, but not W3C...Help! Here is the script and code:

    [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
    <title> </title>


    <meta name="descripti on" content=" "></meta>
    <meta name="keywords" content=" "></meta>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- META Tags Created With: STW META Tag Builder http://www.scrubtheweb .com/abs/ -->

    <script type="text/javascript">
    <!-- Begin
    /* This script and many more are available free online at
    The JavaScript Source!! http://javascript.inte rnet.com
    Created by: Matthew Ogden :: http://www.home.earthl ink.net/~ogden1972/ */

    function d()
    {
    var a = document.form1. miles.value;
    var b = document.form1. gas.value;
    var c = document.form1. days.value;
    var cost = document.form1. cost.value;
    mpg=a/b;
    gpd=b/c;
    mpg= Math.round(mpg* 10)/10;
    gpy=gpd*365;
    co=gpy*19.36;
    cpy=gpy*cost;
    gpd= Math.round(gpd* 1000)/1000;
    gpy= Math.round(gpy* 10)/10;
    cpy= Math.round(cpy* 100)/100;
    co= Math.round(co);
    document.form1. results.value=" Your car is getting "+mpg+" miles per gallon. On the average you use "+gpd+" gallons per day. At that rate of consumption you will burn "+gpy+" gallons per year at a cost of $"+cpy+" per year. In addition, that produces "+co+" pounds of CO2 in one year.";
    }
    // End -->
    </script>
    </head>

    <body>
    <form id="form1" method="post" action="mailto: ">
    <div id="calc">
    <h3>Gasoline Usage Calculator</h3>

    Miles Traveled:
    <input type="text" size="8" id="miles" name="miles"></input>
    Gallons of Gas:
    <input type="text" size="6" name="gas"></input> <br></br>
    Cost of Gas: $
    <input type="text" size="4" name="cost"></input>
    Days Between Fill-Ups:
    <input type="text" size="6" name="days"></input> <br></br>
    <input type="button" value="Calculat e" onclick="d()"></input><br></br><input type="reset" value="Clear"></input><br></br>
    <strong>Results </strong><br></br>
    <textarea name="results" rows="5" cols="55" style="border-width:0;overflo w:hidden"onfocu s="this.blur()" >
    </textarea>

    </div>
    </form>

    <p>
    Free JavaScripts provided
    by <a href="http://javascriptsourc e.com">The JavaScript Source</a>
    </p>

    <!-- Script Size: 2.28 KB -->

    </body>
    </html>[/HTML]

    Thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    To use the script with an id, use document.getEle mentById("form1 ")... in place of document.form1. ..

    Comment

    Working...