Thanks for the responses.. i put a live version of the code.. to see if that helps resolve this. It is here:
http://www.zacharydesigns.com/sandbox/calculatorJS.html
I updated the following code to reflect what was offered as an answer.. however this just returns zero
I am having trouble wrapping my head around creating a simple equation in javaScript. What I am trying to achieve is to have a=(x/z)*y
.
x = user input
z = total of all input
y = defined number (in this case 300)
What I came up with is
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
function update()
{
var a = $("#productOne").val(); // '#' identify IDs as in CSS
var b = $("#productTwo").val();
var c = $("#productThree").val();
var productTotal = Math.floor(a/(a+b+c));
$("#productTotal").val(productTotal); // Set calculated value in the HTML
}
</script>
<form name="calc" action="#">
<table align="center" border="1">
<tr>
<td align="right">
Product One:
</td>
<td align="left">
<input type="text" name="productOne" id="productOne" size="5" /></td>
<td align="right">
Product Two:
</td>
<td align="left">
<input type="text" name="productTwo" id="productTwo" size="5" /></td>
<td align="right">
Product Three:
</td>
<td align="left">
<input type="text" name="productThree" id="productThree" size="5" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="Calculate" onclick="update();return false;" />
</td>
</tr>
<td align="right">
Product Total:</td>
<td align="left">
<input type="text" name="productTotal" id="productTotal" size="6" readonly="readonly" /></td>
</tr></table>
</form>
which I am not sure is even close. Can someone help guide me through this, please?