...

View Full Version : basic math, document.write and input fields



subhailc
07-07-2004, 12:02 AM
hi. i have forgotten what little i once knew of js. trying to write a function that sets 2 variables which are the product of 2 text input form fields, and performs a single simple formula either onlostfocus or onmouseout or onclick of something (anything), then displays the answer either via an alert box or just document.write

solely for clarification, here's a hamfisted psuedo-script:



<html>
<head>
<script>
var a = form1.field1.value;
var b = form1.field2.value;
function calc(); {
document.write = ('(((((a*a)*a)/((b+1)-a))*a)+(100/b))/2)');
}
</script>
</head>
<body>
<form id="form1" name="form1" method="getblahblah">
<input type="text" name="field1" size="2" id="field1" value="1" onlostfocus="calc()";>
<input type="text" name="field2" size="2" id="field1" value="1"
onlostfocus="calc()";>>
</form>
</body>
</html>

dumpfi
07-07-2004, 01:38 AM
<html>
<head>
<script type="text/javascript">
function calc() {
var a = document.form1.field1.value;
var b = document.form1.field2.value;

document.write((a * a * a * a / ((b + 1) - a) + 100 / b) / 2);
}
</script>
</head>
<body>
<form name="form1" method="getblahblah">
<input type="text" name="field1" size="2" value="1" onBlur="calc()";>
<input type="text" name="field2" size="2" value="1" onBlur="calc()";>>
</form>
</body>
</html>

squirellplaying
07-07-2004, 03:09 AM
Yes. What he said^^. You're getting the variable values before the user sets them or that part of the html is even created.

subhailc
07-07-2004, 11:54 AM
thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum