Code for a calculation

A

Amy

My boss has requested that I create a web page that contains 3 fields. Field
A is entered by the user. Field B is entered by the user. The result of the
calculation between Field A and B produces a result (D) which then displays
OK or not OK in Field C.

The calculation is as follows:

A+B=X
(a/x)*100=D

If D is greater than 10, Field C displays "OK", if it is less than 10, Field
C displays "Not OK".

I am clueless. Anyone have any ideas??
 
T

Trevor L.

Amy said:
My boss has requested that I create a web page that contains 3
fields. Field A is entered by the user. Field B is entered by the
user. The result of the calculation between Field A and B produces a
result (D) which then displays OK or not OK in Field C.

The calculation is as follows:

A+B=X
(a/x)*100=D

If D is greater than 10, Field C displays "OK", if it is less than
10, Field C displays "Not OK".

I am clueless. Anyone have any ideas??

<html>
<head>
<script type="text/javascript">
function sendform()
{
with (document.form1)
{
result.value = +val1.value * 100 / (val1.value + val2.value)

/* This is the test
A = val1
B = val2
C = result
D = A * 100 / (A+B)

If D >= 10, C displays "OK"
If D < 10, C displays "Not OK"
*/
checked.value = (result.value >= 10) ? "OK" : "Not OK"
}

// other stuff here
}
</script>
</head>
<body>

<form name="form1" action="">
<table>
<tr>
<td>A: </td>
<td><input type="text" id="val1" value="10"/></td>
</tr>
<tr>
<td>B: </td>
<td><input type="text" id="val2" value="3" /></td>
</tr>
<tr>
<td>Check Box: </td>
<td><input type="text" id="checked" size="10" /></td>
</tr>
<tr>
<td>D: </td>
<td><input type="text" id="result" size="20" /></td>
</tr>
</table>
<input type="button" id="Check" value="Check" onclick="sendform()" />
</form>

</body>
</html>
 
T

Trevor L.

This should read

/* This is the test
A = val1
B = val2
C = checked
D = result
Set D = A * 100 / (A+B)
If D >= 10, C displays "OK"
If D < 10, C displays "Not OK"
*/

But this was only a comment trying to explain what was done. The code should
be correct
 
T

Trevor L.

Amy said:
Thank you, thank you, thank you - You are a genius!!

Aw, shucks.

No, but honestly, this is a common query, so I'll keep my code to post to
future enquiries.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top