Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form calculations 1

Status
Not open for further replies.

terpster

MIS
Mar 18, 2002
26
0
0
US
I'm very new to java script. But I figure I have to learn somehow.

What I'm trying to do is take the inputed values from a form and print out the calcuated value. I would guess it's something similar to an order form.

eg of what I'm trying to do?
<FORM>
<P>
<table>
<tr><td width="50%"><LABEL for="length">Length: </LABEL></td>
<td width="50%"><INPUT type="text" id="Length"></td></tr>
<tr><td width="50%"><LABEL for="width">width: </LABEL></td>
<td width="50%"><INPUT type="text" id="width"></td></tr>
<tr><td width="50%"><LABEL for="height">height: </LABEL></td>
<td width="50%"><INPUT type="text" id="height"></td></tr><BR>

</table>
</P>

</FORM>


any and all help will be much appreciated.
 
First of all, I have to say your code is horrible to read because of the caps. But anyways, to answer your question we have to know what it is you want to accomplish. Do you want to multiply the width by the height, or add something, or what?

To learn the basics of javascript, go to . That is a really good place to learn the basics.

Peace out,
Peace Co.
 
<html>
<head>
<script language="JavaScript">
function calculate()
{
var l;
var w;
var h;

l=parseInt(document.forms[0].length.value);
w=parseInt(document.forms[0].width.value);
h=parseInt(document.forms[0].height.value);

var r=0;
r=l+w+h;
document.forms[0].result.value=r;
}

</script>
</head>
<body>
<FORM id="frmCalculate">
<P>
<table>
<tr><td width="50%"><LABEL for="length">Length: </LABEL></td>
<td width="50%"><INPUT type="text" id="length"></td></tr>
<tr><td width="50%"><LABEL for="width">width: </LABEL></td>
<td width="50%"><INPUT type="text" id="width"></td></tr>
<tr><td width="50%"><LABEL for="height">height: </LABEL></td>
<td width="50%"><INPUT type="text" id="height"></td></tr><BR>
<tr><td width="50%"><LABEL for="result">result: </LABEL></td>
<td width="50%"><INPUT type="text" id="result"></td></tr><BR>
<tr><td width="50%" colspan="2">
<INPUT type="button" onclick="calculate();" value="Calculate!"></td></tr><BR>
</table>
</P>

</FORM>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top