Click to See Complete Forum and Search --> : What am I doing wrong...won't compute


jdm
03-18-2004, 07:02 AM
none

TheBearMay
03-18-2004, 07:26 AM
Where to start....The code below will work... Main problem was that your text boxes were not named or id'ed the same as what your function was expecting....


<HTML>
<HEAD>
<TITLE>Air Pressure Computation Form</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from incompatible browsers
<!-- - 03/20/04 - The purpose of this code is to
compute the length times the width then multiply that by 14.7 psi
to get the air pressure of an object -->

function computeForm(form) {
var l=eval(form.len.value);
var w=eval(form.width.value);
var p=14.7;
var ANS=l*w*p;
form.ans.value=ANS;
}
</SCRIPT>

<BGCOLOR="#FF00FF" TOPMARGIN="2">

<TR>
<TD WIDTH="100%">

<TABLE BORDER="1" WIDTH="50%" BGCOLOR="#FF99FF" CELLSPACING="0" CELLPADDING="4" BORDERCOLOR="#6495ED">
<TR>
<TD WIDTH="100%">

<CENTER>
<FORM method="post">

<TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0" WIDTH="320">
<TR>
<TD WIDTH="100%" BGCOLOR="#FF66FF" ALIGN="center">
<FONT FACE="Tahoma"><B>Air Pressure Computation Form</B></FONT>
</TD>
</TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#FF33FF" ALIGN="center">

<TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0">
<TR>
<TD WIDTH="100%"><FONT FACE="Tahoma"><B>Length x Width x 14.7 psi</B><FONT SIZE="3">
</TR>
<TR>
<TD WIDTH="100%">
<FONT FACE="Tahoma">
<INPUT ID="len" SIZE="3" VALUE="" STYLE="font size: 12 pt; font face: Tahoma"> L
<INPUT TYPE="button" VALUE=" * ">
<INPUT ID="width" TYPE="text" SIZE="3" STYLE="font size: 12 pt; font face: Tahoma"> W
<INPUT TYPE="button" VALUE="* ">
14.7 psi
<INPUT TYPE="button" VALUE="Compute" onClick="computeForm(this.form);">
<INPUT TYPE="text" ID="ans" SIZE="7" STYLE="font size 12 pt; font face: Tahoma"> Answer
</TD>
</TR>
</TABLE>

</TD>
</TR>
<TR>
<TD BGCOLOR="#DDA0DD" ALIGN="center">
<INPUT TYPE="reset" VALUE="Reset">
</TD>
</TR>
</TABLE>

</FORM>
</CENTER>
</BODY>
</HTML>

jaegernaut
03-18-2004, 07:40 AM
A couple of additional comments, you don't have an opening Body tag or a closing Head tag.

This code create a JS error:
<!-- - 03/20/04 - The purpose of this code is to
compute the length times the width then multiply that by 14.7 psi
to get the air pressure of an object --> You should use Javascript comments after the initial <!--, and to hide the code the --> must go after the JS code.

Using TheBearMay's code with these revisions would look like this:
<HTML>
<HEAD>
<TITLE>Air Pressure Computation Form</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from incompatible browsers
/* - 03/20/04 - The purpose of this code is to
compute the length times the width then multiply that by 14.7 psi
to get the air pressure of an object */

function computeForm(form) {
var l=eval(form.len.value);
var w=eval(form.width.value);
var p=14.7;
var ANS=l*w*p;
form.ans.value=ANS;
}
// -->
</SCRIPT>
</head>
<Body BGCOLOR="#FF00FF" TOPMARGIN="2">